PSP2.1 | 个人开发流程 | 预估耗费时间(分钟) | 实际耗费时间(分钟) |
---|---|---|---|
Planning | 计划 | 15 | 10 |
· Estimate | 明确需求和其他相关因素,估计每个阶段的时间成本 | 30 | 40 |
Development | 开发 | 200 | 150 |
· Analysis | 需求分析 (包括学习新技术) | 60 | 60 |
· Design Spec | 生成设计文档 | 60 | 50 |
· Design Review | 设计复审 | 10 | 15 |
· Coding Standard | 代码规范 | 10 | 10 |
· Design | 具体设计 | 45 | 35 |
· Coding | 具体编码 | 120 | 140 |
· Code Review | 代码复审 | 30 | 20 |
· Test | 测试(自我测试,修改代码,提交修改) | 20 | 25 |
Reporting | 报告 | 60 | 50 |
· | 测试报告 | 15 | 10 |
· | 计算工作量 | 5 | 5 |
· | 并提出过程改进计划 | 10 | 15。 |
代码:
package WordF;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class WordCount {
private Map<String,Integer> WordFre; //单词词频
String text;
public WordCount(String text) {
this.text = text;
}
public boolean isWord(String s)//判断是否是单词
{
if(s.matches("[a-zA-Z]{4}[a-zA-Z0-9]*"))//利用正则表达式判断是否是单词
return true;
else
return false;
}
public List<Entry<String, Integer>> WordFre()
{
WordFre= new HashMap<String, Integer>();
String t = text;
String[] words = t.split("\\s"); // 将字符串进行分割
for (int i = 0; i < words.length; i++) {
if (isWord(words[i])) { // 判断是否为单词,调用isWord函数
words[i] = words[i].trim().toLowerCase();//将大写字母变成小写字母
if (WordFre.get(words[i]) == null) { // 判断之前Map中是否出现过该字符串
WordFre.put(words[i], 1);// 如果为新单词,放入map中作为key值,value设为1
} else
WordFre.put(words[i], WordFre.get(words[i]) + 1);//如果出现过的单词则将value值+1
}
}
List<Map.Entry<String, Integer>> list = new ArrayList<Map.Entry<String, Integer>>(WordFre.entrySet());//用list列表储存键值
list.sort(new Comparator<Map.Entry<String, Integer>>() {//对list排序
@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();//降序排列
}
});
return list;
}
}
package WordF;
import java.io.*;
public class FileRead {
public String FileInput(String Path) throws IOException {
File fi =new File(Path);
if(!fi.exists() || fi.isDirectory()) { //判断文路径文件和目录是否存在
System.out.println("您输入的文件名有误!请重新输入!");
throw new FileNotFoundException(); //文件是否存在,不存在则抛出异常
}
FileInputStream files=new FileInputStream(fi);
Long filelength =fi.length();
byte[] by =new byte[filelength.intValue()];
StringBuffer buf = new StringBuffer();
if(fi.isFile()&&fi.exists()) {
if(files.read(by)!=-1) { //当read =-1 结束
buf.append(new String(by));
}
}files.close();
return buf.toString();
}
}
package WordF;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main {
public static void main(String[] args)throws IOException {
// TODO Auto-generated method stub
FileRead fi=new FileRead();
Scanner result = new Scanner(System.in);
System.out.println("请输入你要WordFrequent的路径:");
String path = result.next();
result.close();
String text =fi.FileInput(path);
WordCount wc=new WordCount(text);
List<Map.Entry<String, Integer>> WordFre=wc.WordFre();
int WordSum= WordFre.size();
for (int i = 0; i < WordSum; i++) {
System.out.println("【"+WordFre.get(i).getKey()+"】 :"+WordFre.get(i).getValue()+"\n");
}
}
}
原文:https://www.cnblogs.com/ysm0301/p/9751621.html