编程作业
第二部分
这个作业属于哪个课程 | 软工2018计科二班 |
---|---|
这个作业要求在哪里 | 编程作业 |
这个作业的目标 | 学习软件开发过程及gitee使用 |
学号 | 20188440 |
项目地址
PSP表格
psp2.1 | Personal Software Process Stages | 预估耗时(min) | 实际耗时(min) |
---|---|---|---|
Planning | 计划 | 20 | 25 |
Estimate | 估计这个任务需要多少时间 | 20 | 20 |
Develoment | 开发 | 1000 | 1140 |
Analysis | 需求分析 | 200 | 240 |
Design Spec | 生成设计文档 | 30 | 40 |
Design Review | 设计复审 | 25 | 20 |
Coding Standard | 代码规范设计 | 60 | 70 |
Design | 具体设计 | 60 | 70 |
Coding | 具体编码 | 400 | 450 |
Code Review | 代码复审 60 | 60 | |
Test | 测试 | 60 | 60 |
Reporting | 报告 | 30 | 30 |
Test Repor | 测试报告 20 | 15 | |
Size Measuremen | 计算工作量 | 20 | 15 |
Postmortem&Process Improvement Plan | 事后总结,并提出过程改进计划 | 20 | 25 |
合计 | 1025 | 1140 | |
解题思路描述 | |||
1.文件数处理,将文件数据直接从文件中取出,获得结果后将结果拼接成字符串,利用bufferedwriter写入文件中,读取文件数据使用bufferedreader。 | |||
2.文件中字符串的长度直接使用length()方法获取,在返回字符串长度。 | |||
3.单词数的统计采用正则表达式来分割字符串,再用matches()方法获取匹配的单词,忽略字符数小于4,数字开头等。在利用map<string ,integer>,将单词和对应出现次数加入wordMap中。 | |||
4.统计行数,利用bufferedreader中的readline()方法,整行读取,读取整行数据同时判断是否为空行,为空则忽略改行。直到最后为空,文件完全读取。 | |||
5.对单词出现的频率进行排序。利用map<string,intger>对象,利用sort方法和匿名内部类的比较器进行排序,最后返回一个list对象。 | |||
6.将数据拼接成完整字符串,利用bufferedwriter写入对应的文件中。 |
代码规范链接
设计与实现过程
public static String charactersCount(String filePath)
{
BufferedReader bReader=null;
StringBuilder str=null;
try
{
FileReader reader=new FileReader(filePath);
bReader=new BufferedReader(reader);
str=new StringBuilder();
int flag;
//str.append(bufferedReader.read());
while ((flag=bReader.read())!=-1)
{
str.append((char)flag);
}
} catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}finally
{
try
{
bReader.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
return str.toString();
}
public static int charactersNumberCount(String str)
{
char[] ch = str.toCharArray();
int num = 0;
for(int i = 0; i < ch.length; i++) {
if(ch[i] >= 0 && ch[i] <= 127) {
num++;
}
}
return num;
}
public static int linesNumberCount(String filePath)
{
File file=new File(filePath);
int count=0;
if(file.exists())
{
try
{
BufferedReader in = new BufferedReader(new FileReader(file));
String line;
while((line = in.readLine()) != null)
{
if(!line.equals("") )
{
count ++;
}
}
//System.out.print(count);
in.close();
}
catch(FileNotFoundException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
return count;
}
public List<Map.Entry<String,Integer>> SortMap()
{
List<Map.Entry<String,Integer>> wordList=new ArrayList<Map.Entry<String, Integer>>(wordsMap.entrySet());
Collections.sort(wordList, new Comparator<Map.Entry<String, Integer>>()
{
@Override
public int compare(Map.Entry<String, Integer> map1, Map.Entry<String, Integer> map2)
{
if (map1.getValue().equals(map2.getValue()))
{
return map1.getKey().compareTo(map2.getKey());
}
else
{
return map2.getValue()-map1.getValue();
}
}
});
return wordList;
}
}
心路历程
这次作业我碰到更多的麻烦,也学了更多东西, git的使用,更好的规划自己的时间。。对于软件的开发也更加清晰。