系统分析与设计结对项目
1.合作者
201631062320 201631062420
2.GitHub项目地址
https://github.com/changrui520/homework
3.本次作业链接地址
https://edu.cnblogs.com/campus/xnsy/2018Systemanalysisanddesign/homework/2188
4.结对psp表格
| PSP2.1 | PSP阶段 | 预估耗时(分钟) | 实际耗时(分钟) |
| · Planning | · 计划 | 15 | 10 |
| · Estimate | · 估计这个任务需要多少时间 | 30 | 20 |
| · Development | · 开发 | 60 | 40 |
| · Analysis | · 需求分析 (包括学习新技术) | 5 | 5 |
| · Design Spec | · 生成设计文档 | 5 | 5 |
| · Design Review | · 设计复审 (和同事审核设计文档) | 10 | 5 |
| · Coding | · 代码规范 (为目前的开发制定合适的规范) | 10 | 5 |
| · Code Review | · 具体设计 | 15 | 20 |
| · Test | · 具体编码 | 60 | 40 |
| · Reporting | · 代码复审 | 10 | 5 |
| · Test Report | · 报告 | 10 | 5 |
| · Size Measurement | · 测试报告 | 30 | 20 |
| · Postmortem & Process | · 计算工作量 | 15 | 10 |
| · Improvement Plan | · 事后总结, 并提出过程改进计划 | 10 | 5 |
| · 合计 | 270 |
250 |
5.互审代码结果
根据阿里巴巴p3c开发手册进行互审后我们发现的不符合规范的地方有以下几点:
(1)接口中的方法和属性不要加任何修饰符号,保持代码的整洁性并加上有效的javadoc注释
(2)不允许任何未定义的常量直接出现在代码中
(3)类、类属性、类方法的注释必须使用javadoc规范
(4)不能使用尾行注释,必须另起一行
(5)数组定义时必须使用 String[] arg 格式,不得使用 String arg [] 格式
(6)在注释的双斜线和注释内容之间必须有一个空格
(7)方法参数在定义和传入时多个参数逗号后必须加空格
(8)

(9)所有的类都必须添加创建者和创建日期
6.设计过程
使用IO流中的字符流实现。
Main类:读取用户录入的内容,根据内容调用utils类中的相应方法。
Utils类:负责具体处理。
charNum方法:统计字符数
wordNum方法:统计单词数
lineNum方法:统计行数
markLineNum方法:统计空行、注释行
floder方法:递归处理文件夹中符合条件的文件
graphical方法:显示一个图形界面,用户可以在图形界面中操作。
因为以前从来没有学习过JAVA中的GUI和AWT,所以只能一点一点边学边做,目前还未完成,只做了一个大体的界面:

7.代码说明
Main函数:
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String currentCommand = null;
String[] commands = null;
while (true) {
try {
currentCommand=br.readLine();
// 判断命令是否为空
if (!isNullCommand(currentCommand)) {
commands = currentCommand.split(" ");
// 判断是否为3个词或四个词
if (isThreeOrFour(commands)) {
// 判断第一个词是否为wc.exe
if (isWc(commands)) {
// 判断第二个词
switch (commands[1]) {
case "-c":
System.out.println(charNum(commands[2]));
break;
case "-w":
System.out.println(wordNum(commands[2]));
break;
case "-l":
System.out.println(lineNum(commands[2]));
break;
case "-a":
System.out.println(markLineNum(commands[2]));
break;
case "-s":
System.out.println(floder(commands[3],commands[2]));
break;
default:
System.out.println("格式错误,请重新输入");
break;
}
} else {
System.out.println("格式错误,请重新输入");
break;
}
} else {
System.out.println("格式错误,请重新输入");
break;
}
} else {
System.out.println("错误,命令不能为空");
break;
}
} catch (FileNotFoundException e) {
System.out.println("找不到文件");
} catch (IOException e) {
System.out.println("打开文件失败");
}
}
}
/**
* 判断命令是否为空
* @param currentCommand
* @return
*/
private static boolean isNullCommand(String currentCommand){
if(currentCommand==null){
return true;
}else {
return false;
}
}
/**
* 判断是否为三个或四个词
* @param commands
* @return
*/
private static boolean isThreeOrFour(String [] commands){
if(commands.length==3||commands.length==4){
return true;
}else {
return false;
}
}
/**
* //判断第一个词是否为wc.exe
* @param commands
* @return
*/
private static boolean isWc(String[] commands){
if("wc.exe".equals(commands[0])){
return true;
}else {
return false;
}
}
}
Utils类:
public class Utils {
public static Integer charNum(String fileName) throws IOException {
Integer num = 0;
BufferedReader br = new BufferedReader(new FileReader(fileName));
BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt", true));
int c;
// 统计字符数
while ((c = br.read()) != -1) {
if ((char) c != '\r' && (char) c != '\n') {
num++;
}
}
// 写出结果
bw.write(fileName + "," + "字符数" + ":");
bw.write(num.toString() + "\r\n");
// 关流
br.close();
bw.close();
return num;
}
public static Integer wordNum(String fileName) throws IOException {
Integer num = 0;
BufferedReader br = new BufferedReader(new FileReader(fileName));
BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt", true));
String currentLine = null;
// 储存分割后的数组
String[] words = null;
while ((currentLine = br.readLine()) != null) {
currentLine = currentLine.replaceAll("[^_a-zA-Z]", " ");
words = currentLine.split(" ");
for (String word : words) {
// 去掉空格,和空字符
if (!" ".equals(word) && !"".equals(word)) {
num++;
}
}
}
// 写出结果
bw.write(fileName + "," + "单词数" + ":");
bw.write(num.toString() + "\r\n");
// 关流
br.close();
bw.close();
return num;
}
public static Integer lineNum(String fileName) throws IOException {
Integer num = 0;
BufferedReader br = new BufferedReader(new FileReader(fileName));
BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt", true));
while ((br.readLine()) != null) {
num++;
}
// 写出结果
bw.write(fileName + "," + "行数" + ":");
bw.write(num.toString() + "\r\n");
// 关流
br.close();
bw.close();
return num;
}
public static Integer markLineNum(String fileName) throws IOException {
Integer num = 0;
BufferedReader br = new BufferedReader(new FileReader(fileName));
BufferedWriter bw = new BufferedWriter(new FileWriter("result.txt", true));
String line = null;
while ((line = br.readLine()) != null) {
line = line.replaceAll("\\s|\r|\n", "");
if (isMark(line)) {
num++;
}
}
// 写出结果
bw.write(fileName + "," + "空行、注释行数量" + ":");
bw.write(num.toString() + "\r\n");
// 关流
br.close();
bw.close();
return num;
}
public static String floder(String command, String floderName) throws IOException {
File file = new File(floderName);
if (file.exists()) {
if (!file.isDirectory()) {
// 如果是文件且以.c结尾,就调用相应函数
if (file.getName().endsWith(".c")) {
switch (command) {
case "-c":
charNum(file.getPath());
break;
case "-w":
wordNum(file.getPath());
break;
case "-l":
lineNum(file.getPath());
break;
case "-a":
markLineNum(file.getPath());
break;
default:
return "格式错误,请重新输入";
}
}
} else {
// 如果是文件夹,则递归调用
File[] files = file.listFiles();
for (File file1 : files) {
floder(command, file1.getPath());
}
}
return "ok";
} else {
return "文件夹不存在";
}
}
private static boolean isMark(String line) {
// 判断是否为空行
if (line == null || "".equals(line)) {
return true;
}
// 判断是否以”*/“开头
if (line.endsWith("*/")) {
return true;
}
// 判断是否以”//“开头
if (line.startsWith("//")) {
return true;
}
// 判断是否以”/*“结尾
if (line.startsWith("/*")) {
return true;
}
return false;
}
}
8.测试
共计12个测试用例:
1.统计字符数:wc.exe -c file.c
结果:


2.统计单词数:wc.exe -w file.c
结果:


3.统计行数:wc.exe -l file.c
结果:


4.统计空行、注释行:wc.exe -a file.c
结果:


5.递归处理文件夹


6.a.exe -c file.c
结果:

7.wc.exe -x file.c
结果:

8.wc.exe
结果:

9.wc.exe -c file.c file.c
结果:

10.wc.exe -c a.c
结果:

11.空命令
结果:

12..wc.exe -c file.java
结果:

9.总结
通过这次结对编程我学会了很多,有时候自己的代码写完以后只有自己能看懂,想要让他人也容易看懂,必须遵守编程规范,并加上简单易懂的注释。以后再公司里做大项目,有些工作不是一个人能完成的,这时候需要全体人员遵守编程规范,以后整合、测试、修改时才能更有序,更方便。

浙公网安备 33010602011771号