Myapp.exe -n 10
Myapp.exe -r 10
生成的题目存入执行程序的当前目录下的Exercises.txt文件,格式如下:
1. 四则运算题目1
2. 四则运算题目2
……
其中真分数在输入输出时采用如下格式,真分数五分之三表示为3/5,真分数二又八分之三表示为2’3/8在生成题目的同时,计算出所有题目的答案,并存入执行程序的当前目录下的Answers.txt文件,格式如下:
1. 答案1
2. 答案2
特别的,真分数的运算如下例所示:1/6 + 1/8 = 7/24。程序支持对给定的题目文件和答案文件,判定答案中的对错并进行数量统计,输入参数如下:
Myapp.exe -e <exercisefile>.txt -a <answerfile>.txt
统计结果输出到文件Grade.txt,格式如下:
Correct: 5 (1, 3, 5, 7, 9)
Wrong: 5 (2, 4, 6, 8, 10)
其中“:”后面的数字5表示对/错的题目的数量,括号内的是对/错题目的编号。为简单起见,假设输入的题目都是按照顺序编号的符合规范的题目。
PSP2.1 | Personal Software Process Stages | 预估耗时(分钟) | 实际耗时(分钟) |
---|---|---|---|
Planning | 计划 | 45 | 45 |
· Estimate | · 估计这个任务需要多少时间 | · 45 | · 45 |
Development | 开发 | 960 | 645 |
· Analysis | · 需求分析 (包括学习新技术) | · 120 | · 150 |
· Design Spec | · 生成设计文档 | · 45 | · 40 |
· Design Review | · 设计复审 (和同事审核设计文档) | · 45 | · 30 |
· Coding Standard | · 代码规范 (为目前的开发制定合适的规范) | · 30 | · 45 |
· Design | · 具体设计 | · 120 | · 90 |
· Coding | · 具体编码 | · 480 | · 200 |
· Code Review | · 代码复审 | · 60 | · 50 |
· Test | · 测试(自我测试,修改代码,提交修改) | · 60 | · 80 |
Reporting | 报告 | 105 | 105 |
· Test Report | · 测试报告 | · 45 | · 45 |
· Size Measurement | · 计算工作量 | · 30 | · 30 |
· Postmortem & Process Improvement Plan | · 事后总结, 并提出过程改进计划 | · 30 | · 30 |
合计 | 1110 |
835 |
关键代码:
逆波兰的求值步骤:
- 初始化一个空堆栈
- 如果字符是一个操作数,把它压入栈
- 如果字符是一个操作符号,弹出两个操作数,执行恰当操作,然后把结果压入堆栈,如果不能够弹出两个操作数,那么后缀表达式的语法错误。
- 到后缀表达式末尾,从堆栈中弹出结果,若后缀表达式格式正确,那么堆栈应该为空。
package com.SCL;
import java.util.*;
public class Expression {
private ArrayList expression = new ArrayList();// 存储中序表达式
private ArrayList right = new ArrayList();// 存储右序表达式
private String expresult ;// 结果
public Expression() {
}
public String getExpresult() {
return expresult;
}
// 依据输入信息创建对象,将数值与操作符放入ArrayList中
Expression(String input) {
StringTokenizer st = new StringTokenizer(input, "+-*/()", true);
while (st.hasMoreElements()) {
String s=st.nextToken();
expression.add(s);
}
}
//将中序表达式转换为右序表达式
private void toRight() {
Stack aStack = new Stack();
String operator;
int position = 0;
while (true) {
if (Calculate.isOperator((String) expression.get(position))) {
if (aStack.top == -1
|| ((String) expression.get(position)).equals("(")) {
aStack.push(expression.get(position));
} else {
if (((String) expression.get(position)).equals(")")) {
while(true){
if (aStack.top != -1&&!((String) aStack.top()).equals("(")) {
operator = (String) aStack.pop();
right.add(operator);
}else{
if(aStack.top != -1)
aStack.pop();
break;
}
}
} else {
while(true){
if (aStack.top != -1&& Calculate.priority((String) expression
.get(position)) <= Calculate
.priority((String) aStack.top())
) {
operator = (String) aStack.pop();
if (!operator.equals("("))
right.add(operator);
}else{
break;
}
}
aStack.push(expression.get(position));
}
}
} else
right.add(expression.get(position));
position++;
if (position >= expression.size())
break;
}
while (aStack.top != -1) {
operator = (String) aStack.pop();
if(!operator.equals("("))
right.add(operator);
}
}
// 对右序表达式进行求值
boolean getResult() {
this.toRight();
Stack aStack = new Stack();
String op1, op2, is = null;
String temp="";
Iterator it = right.iterator();
while (it.hasNext()) {
is = (String) it.next();
if (Calculate.isOperator(is)) {
op1 = (String) aStack.pop();
op2 = (String) aStack.pop();
temp = Calculate.twoResult(is, op1, op2);
double td = Double.parseDouble(temp.trim());
if(td==999999.0){
return false;
}
aStack.push(temp);
} else
aStack.push(is);
}
expresult = (String)aStack.pop();
it = expression.iterator();
while (it.hasNext()) {
String tempstr = (String) it.next();
System.out.print(tempstr);
} System.out.println("=" ); //expresult为计算结果 return true; }}
正常测试
生成三个文档
错误测试
生成10000道题
项目总结
因为平时敲代码比较少,很多java基础知识都忘记了,导致很多数据类型不匹配的错误,很头疼,还得翻书看看复习复习
作业中使用了博客的方法来提交作业,对于一直想要搭建博客写博文却一直没有实现的自己无疑是极好的,既能培养自己写博客的习惯,又能提升自己的实践能力。
原文:https://www.cnblogs.com/lock98/p/9721426.html