Week09 "Java program design" The Nineth Time work summary

Source: Internet
Author: User
Tags set time

Week09 "Java Programming" Nineth operations Summary 1. This week's study summary 1.1 summarizes the set and generic related content in the way you like (mind map or other).

For:

2. Written work

Collection of this homework question set

1. Deletion of the specified element in list (title of topic) 1.1 Experimental summary. and answer: List at least 2 ways to delete elements in the list.

For:

    • Experiment Summary: In public static List
    • Methods for deleting elements:
      1. Start deleting from the back of list

      for (int i =list.size()-1 ; i >-1; i--) {        if(list.get(i).equals(str)){            list.remove(i);            }    }

2, the use of iterators, first crossed an element, to determine whether the element satisfies the deletion condition, is to delete it, the loop to determine whether there is the next element. You should call next before you call remove.

for (Iterator<String> iterator = list.iterator(); iterator.hasNext();) {            String  num = (String) iterator.next();            if list.get(i).equals(str))                iterator.remove();        }
2. Count the number of words in the text and sort by the number of occurrences (title of the topic) 2.1 Pseudo-code (not copy code, otherwise deducted)

For:

Establishes the Wordsmap collection while (true) {reads the string to Wordcount=wordmap.Get(word); Gets the number of occurrences of the word if (Word is "!!!!!" ) jumps out of the current read Word loopElse     if(count is not null) Wordmap.put(Word,++count);//Not the first occurrence of the word, the number of times in the original plus a     ElseWordmap.put(Word,1);//The first occurrence of the word, the number is set to 1Print the length of the Wordmap to get the total number of words. List<map.Entry<String,Integer>> list;//Take the key-value pairs in the Wordsmap into the list. Collections.Sort(list) {//Key-value pairs comparison sort  Compare(O1.O2)if(O1.value==o2.value) returns the key comparison result of O1 and O2ElseReturns the value comparison result of O1 and O2}i=0; before cyclic outputTenNumber of words and correspondence, with i>9Make a mark. System. out.println(list);
2.2 Experimental Summary

For:
1, use HashMap set, key put Word (String), value number (Integer)
2. Loop to get the word and the number of occurrences. The first occurrence of the word value is set to 1, otherwise the original value is added one.

Integer count = words.get(word);if(count!=null){count++;words.put(word, count);}else{ words.put(word, 1);}        

3, take Wordsmap key value pairs into list. Use Map.entry

Collections.sort(list,new Comparator<Map.Entry<String, Integer>>() {        @Override        public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {            if(o1.getValue()==o2.getValue())                return o1.getKey().compareTo(o2.getKey());            return o2.getValue()-o1.getValue();        }    });
3. Inverted index (problem set)

The subject is more difficult, do not come out does not matter. But must have own thinking process, must have the submission result.

3.1 Your code runs the result

For:

3.2 pseudocode (Do not copy code, otherwise deduct)

For:

int count=0;//标记行数while(true){读取一行到strline;count++;if(strline为"!!!!!")   跳出读取单词的循环esle        新建Scanner,从strline读取    Map linemap.put(Integer,String);//记录每行的内容    while(strScanner.hasnext()){          读取strSacnner.next()到word中           if           集合中已经存在该单词,则将count直接加到单词对应的行数表中           Map wordMap.put(word,List<Integer>);//记录单词和单词出现的行数集合         else             集合不存在该单词             新建List,将当前行数add进表中,再wordMap.put(word,list);}for(Map.Entry<String,List<Integer>> e:wordMap.entrySet())//循环打印索引       println(e);while   get keyString;//获得查询关键字   for(Map.Entry<String,List<Integer>> e:linemap.entrySet())//在行集合的字符串中   判断是否包含该关键字        if (e.getvalue.comtains(keyString)==true)           println(e.getkey+e.getvalue);       else          println("found 0 results");
3.3 Experimental Summary

A: It takes a long time, but it also has a lot of harvest. First, using two map collections, wordmap the set of rows that contain words and words (List), linemap the number of rows and the contents of each row. Cycle the required elements into two maps. Use Map.entry to traverse the output wordmap to complete the printing of the index. Reads the keyword, operates in linemap, loops over whether the value in each row contains a keyword, and outputs the key and value of the row. The end of the loop has not changed the keyword, the output found O result. Above is my overall idea.

4.Stream and Lambda

Write a student class that has the following properties:

private Long id;private String name;private int age;private Gender gender;//枚举类型private boolean joinsACM; //是否参加过ACM比赛

Creates a collection object, such as a list

4.1 Writing a search method using traditional methods list

A: The search method is as follows:

The results of the operation are as follows:

4.2 Use the stream () in Java8, filter (), collect () to write the code with the same 4.1, and test (to show the test data). When building a test collection, in addition to the normal student object, add some null to the collection, and the method you write should handle the null instead of throwing an exception. (: The school number appears)
For:

    • Test data:
    • function code
    • Run
5. Generic type: Generalstack

The Generalstack of jmu-java-05-collection of title set

5.1 Code for Generalstack interface

Answer: Interface code:

public interface GeneralStack<E> {    E push(E item);            //如item为null,则不入栈直接返回null。    E pop();                   //出栈,如为栈为空,则返回null。    E peek();                //获得栈顶元素,如为空,则返回null.    public boolean empty();//如为空返回true    public int size();     //返回栈中元素数量}
5.2 What are the benefits of generics compared to arraylistintegerstack in previous assignments?

A: The type of element stored in the Arraylistintegerstack must be clearly specified and cannot be changed as soon as it is specified. Using generics, you declare the type of the object using the letters E, T, K, and so on as the type designator. When a generic is used by an interface, the operation of the interface is greatly traversed, reducing the same code for different types, such as Generalstack

3. Code Cloud and PTA

Topic Set: jmu-java-05-Collection

3.1. Code Cloud codes Submission record

In the Code cloud Project, select statistics-commits history-set time period, and then search for and

3.2 PTA Problem set complete situation diagram

Two graphs are required (1. Ranking chart. 2.PTA Submission list diagram)

3.3 Count the amount of code completed this week

The weekly code statistics need to be fused into a single table.

Week Time Total code Amount New Code Volume total number of files number of new files
1 0 0 0 0
2 0 0 0 0
3 0 0 0 0
4 0 0 0 0
5 739 739 16 16
6 1084 345 28 12
7 1180 96 30 2
8 1627 447 35 5
9 1986 359 44 9
10 2350 364 56 12
4. Assess how much you understand Java

Try to evaluate how much you understand Java from the following dimensions

Dimension of degree
Grammar Basic common grammar can be used skillfully, PTA part of the problem can be solved by themselves, part of the need to consult others
Object-oriented design capabilities In object-oriented programming learning, it should be possible to use object-oriented thinking to model the more simple problems to be solved.
Application capabilities Feel the foundation is still not to play, basically have no application ability
Number of lines of code so far 2350

Week09 "Java program design" The Nineth Time work summary

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.