结对项目-四则运算 “软件”之升级版
- 作业要求: https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2213
- github地址:https://github.com/lenkay013/ly013
- 我的姓名学号+博客地址:刘铖 201606120023 https://www.cnblogs.com/lc97/
- 同伴姓名学号+博客地址:刘渊 201606120013 https://www.cnblogs.com/lenkay/
一、程序基本要求如下
- 自动生成题目,单个题目最多不能超过4个运算符,操作数小于100。
- 用户可以输入答案
- 若用户输入答案正确,则提示正确;若答案错误,则提示错误,并要提示正确答案是多少。
二、扩展方向(8选4)
1.程序可以出带括号的正整数四则运算,支持分数,除法保留两位小数
2.用户答题结束以后,程序可以显示用户答题所用的时间
3.答题结束可以显示用户答错的题目个数和答对的题目个数
4.用户在第一次答题时,需要用户输入用户名,用户下次启动后,程序需要记住用户前一次输入的用户名
三、时间记录表
|
PSP2.1 |
Personal Software Process Stages |
Time Senior Student(h) |
Time(h) |
|
Planning |
计划 |
0 |
0 |
|
· Estimate |
估计这个任务需要多少时间 |
25 |
30 |
|
Development |
开发 |
8 |
9 |
|
· Analysis |
需求分析 (包括学习新技术) |
0.2 |
0.3 |
|
· Design Spec |
生成设计文档 |
0 |
0 |
|
· Design Review |
设计复审 |
0.5 |
0.5 |
|
· Coding Standard |
代码规范 |
0.5 |
1.5 |
|
· Design |
具体设计 |
2.8 |
3.7 |
|
· Coding |
具体编码 |
5 |
5 |
|
· Code Review |
代码复审 |
3 |
4 |
|
· Test |
测试(自我测试,修改代码,提交修改) |
1 |
1 |
|
Reporting |
报告 |
0 |
0 |
|
Test Report |
测试报告 |
1 |
2 |
|
·workload |
计算工作量 |
1 |
2 |
|
·correction |
并提出过程改进计划
|
1 |
1 |
四 、结对过程
1.结对成员:姓名:刘渊 201606120013 博客园地址:https://www.cnblogs.com/lenkay/
姓名:刘铖 201606120023 博客园地址:https://www.cnblogs.com/lc97/
2.开发环境:idea
3.扩展方向:
程序可以出带括号的正整数四则运算,支持分数,除法保留两位小数(刘铖)
用户答题结束以后,程序可以显示用户答题所用的时间(刘渊)
答题结束可以显示用户答错的题目个数和答对的题目个数(刘渊)
用户在第一次答题时,需要用户输入用户名,用户下次启动后,程序需要记住用户前一次输入的用户名 (刘铖)
4.结对学习照片:

五、部分代码:
小程序界面代码:
public Main()
{
//创建组件
jb1=new JButton("确认");
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String N=Name.getText();
String M=Number.getText();
name.add(N);
number.add(M);
Start frame = new Start();
frame.setTitle("四则运算训练小程序");
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setVisible(true); // 打开新界面
dispose(); // 关闭当前界面
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
统计分数代码:
int size = list1.size();
int errorSum = size - rightSum;
JFrame resultFrame = new JFrame();
resultFrame.setTitle("运算结果");
resultFrame.setSize(500, 500);
resultFrame.setLocationRelativeTo(null);
resultFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
resultFrame.setVisible(true);
JPanel panel7 = new JPanel();
Timelabel.setText("答题用时为:" + time +" "+"做题总数: " + size + " " + "正确数:" + rightSum + " " + " 最终得分:" + rightSum * 5);
panel7.add(Timelabel);
resultFrame.add(panel7, BorderLayout.NORTH);
JPanel panel = new JPanel();
Font font = new Font(Font.DIALOG, Font.PLAIN, 20);
JTable table = new JTable();
String[] columns = { " 题 目 ", " 你的答案 "," 正确答案 "," 状 态 " };
int[] columnWidth={160,120,120,50};
DefaultTableModel model = new DefaultTableModel(columns, 0);
table.setModel(model);
JScrollPane scrollPane = new JScrollPane(table); //支持滚动
TableColumnModel columnModel=table.getColumnModel();
int count=columnModel.getColumnCount();
javax.swing.table.TableColumn column =columnModel.getColumn(0);
column.setPreferredWidth(columnWidth[0]);
计算做题时间代码:
public class Timer extends JFrame {
private static final long serialVersionUID = 1L;
private static final String INITIAL_LABEL_TEXT = "00:00:00 000";
// 计数线程
private CountingThread thread = new CountingThread();
// 记录程序开始时间
private long programStart = System.currentTimeMillis();
// 程序一开始就是暂停的
private long pauseStart = programStart;
// 程序暂停的总时间
private long pauseCount = 0;
private JLabel label = new JLabel(INITIAL_LABEL_TEXT);
private JButton startPauseButton = new JButton("开始");
private JButton resetButton = new JButton("清零");
String time;
private ActionListener startPauseButtonListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (thread.stopped) {
pauseCount += (System.currentTimeMillis() - pauseStart);
thread.stopped = false;
startPauseButton.setText("暂停");
} else {
pauseStart = System.currentTimeMillis();
thread.stopped = true;
ton("确认");
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String N=Name.getText();
String M=Number.getText();
name.add(N);
number.add(M);
Start frame = new Start();
frame.setTitle("四则运算训练小程序");
frame.setSize(600,400);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setVisible(true); // 打开新界面
dispose(); // 关闭当前界面
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
统计分数代码:
int size = list1.size();
int errorSum = size - rightSum;
JFrame resultFrame = new JFrame();
resultFrame.setTitle("运算结果");
resultFrame.setSize(500, 500);
resultFrame.setLocationRelativeTo(null);
resultFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
resultFrame.setVisible(true);
JPanel panel7 = new JPanel();
Timelabel.setText("答题用时为:" + time +" "+"做题总数: " + size + " " + "正确数:" + rightSum + " " + " 最终得分:" + rightSum * 5);
panel7.add(Timelabel);
resultFrame.add(panel7, BorderLayout.NORTH);
JPanel panel = new JPanel();
Font font = new Font(Font.DIALOG, Font.PLAIN, 20);
JTable table = new JTable();
String[] columns = { " 题 目 ", " 你的答案 "," 正确答案 "," 状 态 " };
int[] columnWidth={160,120,120,50};
DefaultTableModel model = new DefaultTableModel(columns, 0);
table.setModel(model);
JScrollPane scrollPane = new JScrollPane(table); //支持滚动
TableColumnModel columnModel=table.getColumnModel();
int count=columnModel.getColumnCount();
javax.swing.table.TableColumn column =columnModel.getColumn(0);
column.setPreferredWidth(columnWidth[0]);
计算做题时间代码:
public class Timer extends JFrame {
private static final long serialVersionUID = 1L;
private static final String INITIAL_LABEL_TEXT = "00:00:00 000";
// 计数线程
private CountingThread thread = new CountingThread();
// 记录程序开始时间
private long programStart = System.currentTimeMillis();
// 程序一开始就是暂停的
private long pauseStart = programStart;
// 程序暂停的总时间
private long pauseCount = 0;
private JLabel label = new JLabel(INITIAL_LABEL_TEXT);
private JButton startPauseButton = new JButton("开始");
private JButton resetButton = new JButton("清零");
String time;
private ActionListener startPauseButtonListener = new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (thread.stopped) {
pauseCount += (System.currentTimeMillis() - pauseStart);
thread.stopped = false;
startPauseButton.setText("暂停");
} else {
pauseStart = System.currentTimeMillis();
thread.stopped = true;
六、运行效果截图




七、总结感悟
做这个项目综合了很多以前学的知识,让我对旧知识进行了一些回顾学习,收获颇多。

浙公网安备 33010602011771号