实训一

1. 本次作业两名同学的学号,本次作业GIT的提交地址

16012006 刘晨      16012019 姜海睿

码云地址:https://gitee.com/bubblerui/0619/tree/master

2. 两名同学的结对编程过程照片

3. 本次作业的解题思路(可付上 部分 代码或注释,怎么清楚明白怎么写)

代码:

import java.io.BufferedReader;  
import java.io.FileReader;  
import java.util.ArrayList;  
import java.util.Collections;  
import java.util.Comparator;  
import java.util.List;  
import java.util.Map;  
import java.util.Map.Entry;  
import java.util.TreeMap;  
  

public class a {  
  
    public static void main(String[] args) throws Exception {  
          
        BufferedReader br = new BufferedReader(new FileReader("F:\\a.txt"));  
        List<String> lists = new ArrayList<String>();  //存储过滤后单词的列表  
        String readLine = null;
		while((readLine = br.readLine()) != null){  
            String[] wordsArr1 = readLine.split("[^a-zA-Z]");  //过滤出只含有字母的  
            for (String word : wordsArr1) {  
                if(word.length() != 0){  //去除长度为0的行  
                    lists.add(word);  
                }  
            }  
        }  
          
        br.close();  
          
        Map<String, Integer> wordsCount = new TreeMap<String,Integer>();  //存储单词计数信息,key值为单词,value为单词数       
          
        //单词的词频统计  
        for (String li : lists) {  
            if(wordsCount.get(li) != null){  
                wordsCount.put(li,wordsCount.get(li) + 1);  
            }else{  
                wordsCount.put(li,1);  
            }  
  
        }  
          
        SortMap(wordsCount);    //按值进行排序  
      
    }  
      
    //按value的大小进行排序  
    public static void SortMap(Map<String,Integer> oldmap){  
          
        ArrayList<Map.Entry<String,Integer>> list = new ArrayList<Map.Entry<String,Integer>>(oldmap.entrySet());  
          
        Collections.sort(list,new Comparator<Map.Entry<String,Integer>>(){  
            public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {  
                return o2.getValue() - o1.getValue();  //降序  
            }  
        });  
          
        for(int i = 0; i<list.size(); i++){  
            System.out.println(list.get(i).getKey()+ ": " +list.get(i).getValue());  
        }     
    }  
  
}

 本次实验运用知识点:

1.采用FileReader缓冲区读取文本文件

2.Bufferedreader提供了按行读取文本文件的方法readLine()

3.对字符串修改时采用BufferedReaderr和BufferedReader类

4.将一个字符串分割为子字符串,然后将结果作为字符串数组返回。 [^abc] 任何字符,除了 a、b 或 c(否定) [a-zA-Z] a到 z 或 A到 Z,两头的字母包括在内(范围)

5.使用SortMap(wordsCount)按值进行排序

 

4. 本次作业的运行结果截图

5. 小结感受:结对编程真的能够带来1+1>2的效果吗?通过这次结对编程,请谈谈你的感受和体会。

这次结对编程,让我感受了很多,也收获了很多,首先说下自己的搭档,她很认真尽管很忙还是抽空结对,感恩!我自己是基础比较差的,在结对过程中有了提升,尽管有点小烦小累,但是很充实。

两个人在此次实验中明白自己的不足,两个人互相帮助,积极提出自己的意见,有新的想法及时去实践,多一个的帮助,让自己的思维更加清晰,感谢队友的辛勤努力

6. 运用“汉堡包”的方式,评价你的合作伙伴,指出优点、缺点,希望ta提高的地方

优点:

有很强的执行能力,刚想到的思路,马上就会去验证,她的指法也很不错,基础都很扎实

缺点:

对于这次结对编程项目,没有合理安排时间,以至于后面的工作有点盲目,代码质量差。我想这也是我的缺点所在。

posted on 2018-12-11 15:52  nihaoya!!!  阅读(261)  评论(0编辑  收藏  举报