第六组四则运算
1.计划
制作计划预估耗时20分钟,实际计划耗时40分钟
2.需求分析
典型用户:
家长:我希望做一个口算题卡软件,
出一组题,提高孩子口算能力,
以便节省我的时间。
学生:我希望有一个口算题卡软件,
随机出题,做题,提高我的口算能力
以便可以随时查看我的错误题,纠错
3.用户故事
任务一:出题,给一组他(10道)100以内的正整数加减算式
任务二:答题,界面上显示10道题,选中,作答,完成,计时
任务三:统计,对错界面,时间用是多少(秒),正确率
4.复审
感谢同学帮我进行复审,发现我的一些不足之处,指出并及时做出改正。
5.具体设计
用例图:

6.核心代码
package view;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
/**
* @author 作者 Your-Name:
* @version 创建时间: 类说明:小学生口算
*/
public class chenqian39 {
static int i, j, k;
public static void main(String[] args) {
// TODO Auto-generated method stub
Frame f = new Frame("计算器");
Random r = new Random();
Font f1 = new Font("楷体", Font.BOLD, 20);
Font f2 = new Font("宋体", Font.BOLD, 18);
Font f3 = new Font("宋体", Font.BOLD, 16);
f.setBounds(200, 200, 500, 400);
f.setLayout(null);
f.setVisible(true);
// f.setBackground(Color.BLUE);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
Label l1 = new Label("小学生口算系统");
l1.setBounds(190, 40, 180, 30);
l1.setFont(f1);
f.add(l1);
/*
* Label l2 = new Label("功能如下"); l2.setBounds(40,70,80,30); l2.setFont(f2);
* f.add(l2); Label l3 = new Label("1,加法运算"); l3.setBounds(70,110,80,30);
* l3.setFont(f3); f.add(l3); Label l4 = new Label("2,减法运算");
* l4.setBounds(70,150,80,30); l4.setFont(f3); f.add(l4); Label l5 = new
* Label("3,乘法运算"); l5.setBounds(70,190,80,30); l5.setFont(f3); f.add(l5); Label
* l6 = new Label("4,除法运算"); l6.setBounds(70,230,80,30); l6.setFont(f3);
* f.add(l6);
*/
Label l7 = new Label("请选择");
l7.setBounds(40, 100, 70, 30);
l7.setFont(f3);
f.add(l7);
Button b1 = new Button("+");
b1.setBounds(40, 150, 40, 30);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
Frame c1 = new Frame("加法界面");
c1.setBounds(250, 250, 300, 300);
c1.setLayout(null);
c1.setVisible(true);
c1.setBackground(Color.gray);
c1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
c1.setVisible(false);
}
});
TextField t2 = new TextField();
t2.setBounds(20, 50, 50, 30);
t2.setFont(f2);
c1.add(t2);
Button b5 = new Button("+");
b5.setBounds(70, 50, 30, 30);
c1.add(b5);
TextField t3 = new TextField();
t3.setBounds(100, 50, 50, 30);
t3.setFont(f2);
c1.add(t3);
Button b6 = new Button("=");
b6.setBounds(150, 50, 30, 30);
c1.add(b6);
TextField t4 = new TextField();
t4.setBounds(180, 50, 50, 30);
t4.setFont(f2);
c1.add(t4);
t2.setText("" + (r.nextInt(101)));
t3.setText("" + (r.nextInt(101)));
Button b7 = new Button("确定");
b7.setBounds(100, 90, 40, 30);
TextField t5 = new TextField();
t5.setBounds(40, 140, 200, 40);
t5.setFont(f2);
c1.add(t5);
b7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
i = Integer.parseInt(t2.getText());
j = Integer.parseInt(t3.getText());
k = Integer.parseInt(t4.getText());
if (i + j == k) {
t5.setText("回答正确");
t2.setText("" + (r.nextInt(101)));
t3.setText("" + (r.nextInt(101)));
t4.setText("");
} else {
t5.setText("" + i + "+" + "" + j + "正确答案:" + (i + j));
t2.setText("" + (r.nextInt(101)));
t3.setText("" + (r.nextInt(101)));
t4.setText("");
}
}
});
c1.add(b7);
}
});
f.add(b1);
Button b2 = new Button("-");
b2.setBounds(90, 150, 40, 30);
b2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
Frame c2 = new Frame("减法法界面");
c2.setBounds(250, 250, 300, 300);
c2.setLayout(null);
c2.setVisible(true);
c2.setBackground(Color.gray);
c2.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
c2.setVisible(false);
}
});
TextField t21 = new TextField();
t21.setBounds(20, 50, 50, 30);
t21.setFont(f2);
c2.add(t21);
Button b51 = new Button("-");
b51.setBounds(70, 50, 30, 30);
c2.add(b51);
TextField t31 = new TextField();
t31.setBounds(100, 50, 50, 30);
t31.setFont(f2);
c2.add(t31);
Button b61 = new Button("=");
b61.setBounds(150, 50, 30, 30);
c2.add(b61);
TextField t41 = new TextField();
t41.setBounds(180, 50, 50, 30);
t41.setFont(f2);
c2.add(t41);
t21.setText("" + (r.nextInt(101)));
t31.setText("" + (r.nextInt(101)));
Button b71 = new Button("确定");
b71.setBounds(100, 90, 40, 30);
TextField t51 = new TextField();
t51.setBounds(40, 140, 200, 40);
t51.setFont(f2);
c2.add(t51);
b71.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
i = Integer.parseInt(t21.getText());
j = Integer.parseInt(t31.getText());
k = Integer.parseInt(t41.getText());
if (i - j == k) {
t51.setText("回答正确");
t21.setText("" + (r.nextInt(101)));
t31.setText("" + (r.nextInt(101)));
t41.setText("");
} else {
t51.setText("" + i + "-" + "" + j + "正确答案:" + (i - j));
t21.setText("" + (r.nextInt(101)));
t31.setText("" + (r.nextInt(101)));
t41.setText("");
}
}
});
c2.add(b71);
}
});
f.add(b2);
Button b3 = new Button("*");
b3.setBounds(140, 150, 40, 30);
b3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
Frame c1 = new Frame("乘法界面");
c1.setBounds(250, 250, 300, 300);
c1.setLayout(null);
c1.setVisible(true);
c1.setBackground(Color.gray);
c1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
c1.setVisible(false);
}
});
TextField t2 = new TextField();
t2.setBounds(20, 50, 50, 30);
t2.setFont(f2);
c1.add(t2);
Button b5 = new Button("*");
b5.setBounds(70, 50, 30, 30);
c1.add(b5);
TextField t3 = new TextField();
t3.setBounds(100, 50, 50, 30);
t3.setFont(f2);
c1.add(t3);
Button b6 = new Button("=");
b6.setBounds(150, 50, 30, 30);
c1.add(b6);
TextField t4 = new TextField();
t4.setBounds(180, 50, 50, 30);
t4.setFont(f2);
c1.add(t4);
t2.setText("" + (r.nextInt(10)));
t3.setText("" + (r.nextInt(10)));
Button b7 = new Button("确定");
b7.setBounds(100, 90, 40, 30);
TextField t5 = new TextField();
t5.setBounds(40, 140, 200, 40);
t5.setFont(f2);
c1.add(t5);
b7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
i = Integer.parseInt(t2.getText());
j = Integer.parseInt(t3.getText());
k = Integer.parseInt(t4.getText());
if (i * j == k) {
t5.setText("回答正确");
t2.setText("" + (r.nextInt(10)));
t3.setText("" + (r.nextInt(10)));
t4.setText("");
} else {
t5.setText("" + i + "*" + "" + j + "正确答案:" + (i * j));
t2.setText("" + (r.nextInt(10)));
t3.setText("" + (r.nextInt(10)));
t4.setText("");
}
}
});
c1.add(b7);
}
});
f.add(b3);
Button b4 = new Button("/");
b4.setBounds(190, 150, 40, 30);
b4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
Frame c1 = new Frame("除法界面");
c1.setBounds(250, 250, 300, 300);
c1.setLayout(null);
c1.setVisible(true);
c1.setBackground(Color.gray);
c1.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
c1.setVisible(false);
}
});
TextField t2 = new TextField();
t2.setBounds(20, 50, 50, 30);
t2.setFont(f2);
c1.add(t2);
Button b5 = new Button("/");
b5.setBounds(70, 50, 30, 30);
c1.add(b5);
TextField t3 = new TextField();
t3.setBounds(100, 50, 50, 30);
t3.setFont(f2);
c1.add(t3);
Button b6 = new Button("=");
b6.setBounds(150, 50, 30, 30);
c1.add(b6);
TextField t4 = new TextField();
t4.setBounds(180, 50, 50, 30);
t4.setFont(f2);
c1.add(t4);
t2.setText("" + (r.nextInt(20)));
t3.setText("" + (r.nextInt(10) + 1));
Button b7 = new Button("确定");
b7.setBounds(100, 90, 40, 30);
TextField t5 = new TextField();
t5.setBounds(40, 140, 200, 40);
t5.setFont(f2);
c1.add(t5);
b7.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent a) {
i = Integer.parseInt(t2.getText());
j = Integer.parseInt(t3.getText());
k = Integer.parseInt(t4.getText());
if (i / j == k) {
t5.setText("回答正确");
t2.setText("" + (r.nextInt(101)));
t3.setText("" + (r.nextInt(101) + 1));
t4.setText("");
} else {
t5.setText("" + i + "/" + "" + j + "正确答案:" + (i / j));
t2.setText("" + (r.nextInt(101)));
t3.setText("" + (r.nextInt(101) + 1));
t4.setText("");
}
}
});
c1.add(b7);
}
});
f.add(b4);
}
}
7.代码复审
8.测试
9.测试报告
测试过程中出现多次失败,根据系统提示错误进行修改,可以正常运行
10.运行成功界面





11.事后总结
一定要做好计划写代码前,耗时比计划的久。
12.PSP


浙公网安备 33010602011771号