结对项目-四则运算 “软件”之升级版
作业文件上传的github地址为:https://github.com/2392030179/work.git
作业要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2232
结伴同学:黄健科,201606120094,http://www.cnblogs.com/huangjianke123/p/9860721.html
一、从个人项目出发,将程序改装成一个单机带用户界面(不是控制台)的程序,这个程序最基本要达到:
①生成题目,单个题目最多不能超过4个运算符,操作数小于100。
②用户可以输入答案
③若用户输入答案正确,则提示正确;若答案错误,则提示错误,并要提示正确答案是多少。
二、下面附有 8 个相互独立的可以扩展的方向。
①程序可以出带括号的正整数四则运算,支持分数,除法保留两位小数,如:(1/3+1)*2 = 2.67,特别注意:这里是2.67而非2.66,或保持分数形式:8/3
②可以出表达式里含有负整数(负整数最小不小于-100)的题目,且负数需要带括号,用户输入的结果不用带括号。如: 2*(-4) = -8
③用户答题结束以后,程序可以显示用户答题所用的时间
④用户可以选择出题的个数(最多不能超过5个题目),答题结束可以显示用户答错的题目个数和答对的题目个数
⑤用户在第一次答题时,需要用户输入用户名,用户下次启动后,程序需要记住用户前一次输入的用户名
⑥程序可以出单个整数阶乘的题目:如:4!=24
⑦程序可以设置答题时间,时间设置为整数,单位为秒,最大不能超过120秒,若超过了答题时间未答题,则提示:时间已到,不能答题。
⑧程序可以设置皮肤功能,可以改变界面的颜色即可。
三、开发环境
工具:intellij idea
语言:java
四、团队分工
黄建科094:界面代码编写
黄观国075:部分核心算法代码书写
五、运行情况
①输入错误答案时:

②输入答案正确时:
六、实验总结
首先呢,在这次的实验任务中,我组完成了实验的基本需求,也就是建造一个有可视界面的四则运算练习器,其中的无论时设计或编写界面代码,核心算法代码时,我们都碰到了不少的问题(这里就不赘述了),也获得了不少经验。
但事实上,由于时间的关系我们本来的实验计划并不能完整实施,就比如我组原计划在拓展功能上选择:
四个拓展功能加以实现的,但直到博客发布之前我组只完成了基本的需求,⑧号功能已经接近解决,而其他的三个功能也有了初步的眉目,所以在拓展功能实现方面,我组表示遗憾,望谅解。
核心代码展示
public int question(){
Random random=new Random();
int ramNumber1=(int) (Math.random()*100);
int ramNumber2=(int) (Math.random()*100);
int ramNumber3=(int) (Math.random()*100);
String[] operator={"+","-","*","/"};
int operatorIndex1=(int) (Math.random()*4);
int operatorIndex2=(int) (Math.random()*4);
int resultFirst=0;
if (operatorIndex1<operatorIndex2){
resultFirst= arithmetic(ramNumber2,ramNumber3,operator[operatorIndex2]);
resultLast= arithmetic(ramNumber1,resultFirst,operator[operatorIndex1]);
}
else {
resultFirst= arithmetic(ramNumber1,ramNumber2,operator[operatorIndex1]);
resultLast= arithmetic(resultFirst,ramNumber3,operator[operatorIndex2]);
}
// System.out.println(ramNumber1+operator[operatorIndex1]+ramNumber2+operator[operatorIndex2]+ramNumber3+"=");
question=Integer.toString(ramNumber1)+operator[operatorIndex1]+Integer.toString(ramNumber2)
+operator[operatorIndex2]+Integer.toString(ramNumber3)+"=";
return resultLast;
}
界面代码展示
public void mainFram(){
Container container=getContentPane();
setLayout(null);
setBounds(100,100,1200,700);
JButton setQuestion=new JButton("出题");
setQuestion.setFocusPainted(false);
setQuestion.setBounds(350,310,100,50);
setQuestion.setFont(new Font("宋体",Font.BOLD,20));
JButton submitAnswer=new JButton("提交");
submitAnswer.setFocusPainted(false);
submitAnswer.setBounds(750,310,100,50);
submitAnswer.setFont(new Font("宋体",Font.BOLD,20));
JTextField question=new JTextField();
question.setFont(new Font("宋体",Font.BOLD,50));
question.setBounds(350,0,500,250);
JTextField answer=new JTextField();
answer.setFont(new Font("宋体",Font.BOLD,50));
answer.setBounds(350,260,500,50);
JLabel jLabel=new JLabel("答题区:");
jLabel.setFont(new Font("宋体",Font.BOLD,50));
jLabel.setBounds(170,260,500,50);
container.add(setQuestion);
container.add(submitAnswer);
container.add(question);
container.add(answer);
container.add(jLabel);
setVisible(true);
ariOperation=new AriOperation();
result=ariOperation.question();
question.setText(ariOperation.question);
submitAnswer.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
String judge1="回答正确";
String judge2="回答错误,正确答案是:"+Integer.toString(result);
if (Integer.parseInt(answer.getText()) == result)
new Judge(judge1).setVisible(true);
else
new Judge(judge2).setVisible(true);
}
});
setQuestion.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ariOperation=new AriOperation();
result=ariOperation.question();
question.setText(ariOperation.question);
}
});
}
}
七、结对软件过程耗时估计与统计表
PSP2.1 | Personal Software Process Stages | Time Senior Student(h) | Time(h) |
Planning | 计划 | 3 | |
· Estimate | 估计这个任务需要多少时间 | 8 | 18 |
Development | 开发 | 10 | 12 |
· Analysis | 需求分析 (包括学习新技术) | 2 | |
· Design Spec | 生成设计文档 | 1 | |
· Design Review | 设计复审 | ||
· Coding Standard | 代码规范 | ||
· Design | 具体设计 | 4 | 5 |
· Coding | 具体编码 | 16 | |
· Code Review | 代码复审 | ||
· Test | 测试(自我测试,修改代码,提交修改) | ||
Reporting | 报告 | ||
· | 测试报告 | ||
计算工作量 | |||
并提出过程改进计划 |