• 软件工程第三次作业(杨明颢、何亚、陈志艳)小组


    • 题目

              请编写一个能自动生成小学四则运算题目的 “软件”。

              让程序能接受用户输入答案,并判定对错。  

              最后给出总共 对/错 的数量。

    • 需求分析

            - 基本功能

               - 系统可以自动出题(简易四则运算);

               - 用户可以手动输入答案;

               - 显示答案的对错,错误的给出正确答案;

               - 统计四则运算的回答正确题目数。

            - 扩展功能

                在第二次作业的基础上系统设计成可视化的窗口图形。

               设计

            - 系统采用JAVA进行编程调试。

            - 系统能随机生成100以内的四则运算。

            - 本软件采用可视化窗口,提示比较清楚,用户操作简单;

            - 采用模块化思想,把源文件分成几个模块进行封装。

    程序代码:

    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;

    public class rjgc extends JFrame implements ActionListener {

        JLabel jl1, jl2, jl3, jl4, jl5, jl6, jl7, jl8, jl9;
        JTextField jf1, jf2, jf3, jf4;
        JButton jb1, jb5;

        JButton jb;
        JTextField jl21, jl22, jl23, jl24, jl25, jl26, jl27, jl28, jl29, jl210,
                jl211, jl212, jl213, jl214, jl215;

        public rjgc() {
            setTitle("简易四则运算生成器,Design By 杨明颢、何亚、陈志艳");
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(800, 350);
            setLocation(250, 250);
            Container con = getContentPane();
            JPanel pan = new JPanel();

            jb1 = new JButton("出题");
            jb1.addActionListener(this);
            jl1 = new JLabel("?");
            jl2 = new JLabel("?");
            jl3 = new JLabel("答案:");
            jl4 = new JLabel("请输入答案:");
            jl5 = new JLabel("余数:");
            jl6 = new JLabel("?");
            jl7 = new JLabel("余数:");
            jl8 = new JLabel("对/错:");
            jl9 = new JLabel("?");
            jf1 = new JTextField(5);
            jf2 = new JTextField(5);
            jf3 = new JTextField(5);
            jf4 = new JTextField(5);
            jb5 = new JButton("正确答案");
            jb5.addActionListener(this);
            Box b1 = Box.createHorizontalBox();
            b1.add(jb1);
            b1.add(Box.createHorizontalStrut(20));
            b1.add(jf1);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl2);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jf2);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl4);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jf3);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl5);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jf4);
            b1.add(Box.createHorizontalStrut(20));
            b1.add(jb5);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl3);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl6);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl7);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl1);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl8);
            b1.add(Box.createHorizontalStrut(5));
            b1.add(jl9);

            jl21 = new JTextField("0");
            jl22 = new JTextField("0");
            jl23 = new JTextField("0");
            jl24 = new JTextField("0");
            jl25 = new JTextField("0");
            jl26 = new JTextField("0");
            jl27 = new JTextField("0");
            jl28 = new JTextField("0");
            jl29 = new JTextField("0");
            jl210 = new JTextField("0");
            jl211 = new JTextField("0");
            jl212 = new JTextField("0");
            jl213 = new JTextField("0");
            jl214 = new JTextField("0");
            jl215 = new JTextField("0");
            jl21.setEditable(false);
            jl22.setEditable(false);
            jl23.setEditable(false);
            jl24.setEditable(false);
            jl25.setEditable(false);
            jl26.setEditable(false);
            jl27.setEditable(false);
            jl28.setEditable(false);
            jl29.setEditable(false);
            jl210.setEditable(false);
            jl211.setEditable(false);
            jl212.setEditable(false);
            jl213.setEditable(false);
            jl214.setEditable(false);
            jl215.setEditable(false);

            Box b21 = Box.createHorizontalBox();
            b21.add(new JLabel("加法题:"));
            b21.add(jl21);
            b21.add(Box.createHorizontalStrut(50));
            b21.add(new JLabel("对:"));
            b21.add(jl22);
            b21.add(Box.createHorizontalStrut(50));
            b21.add(new JLabel("错:"));
            b21.add(jl23);

            Box b22 = Box.createHorizontalBox();
            b22.add(new JLabel("减法题:"));
            b22.add(jl24);
            b22.add(Box.createHorizontalStrut(50));
            b22.add(new JLabel("对:"));
            b22.add(jl25);
            b22.add(Box.createHorizontalStrut(50));
            b22.add(new JLabel("错:"));
            b22.add(jl26);

            Box b23 = Box.createHorizontalBox();
            b23.add(new JLabel("乘法题:"));
            b23.add(jl27);
            b23.add(Box.createHorizontalStrut(50));
            b23.add(new JLabel("对:"));
            b23.add(jl28);
            b23.add(Box.createHorizontalStrut(50));
            b23.add(new JLabel("错:"));
            b23.add(jl29);

            Box b24 = Box.createHorizontalBox();
            b24.add(new JLabel("除法题:"));
            b24.add(jl210);
            b24.add(Box.createHorizontalStrut(50));
            b24.add(new JLabel("对:"));
            b24.add(jl211);
            b24.add(Box.createHorizontalStrut(50));
            b24.add(new JLabel("错:"));
            b24.add(jl212);

            Box b25 = Box.createHorizontalBox();
            b25.add(new JLabel("总 计:"));
            b25.add(jl213);
            b25.add(Box.createHorizontalStrut(50));
            b25.add(new JLabel("对:"));
            b25.add(jl214);
            b25.add(Box.createHorizontalStrut(50));
            b25.add(new JLabel("错:"));
            b25.add(jl215);

            Box b2 = Box.createVerticalBox();
            b2.add(b21);
            b2.add(b22);
            b2.add(b23);
            b2.add(b24);
            b2.add(b25);

            Box b3 = Box.createVerticalBox();
            b3.add(Box.createVerticalStrut(50));
            b3.add(b1);
            b3.add(Box.createVerticalStrut(25));
            b3.add(b2);
            b3.add(Box.createVerticalStrut(25));
            jb = new JButton("清除记录");
            jb.addActionListener(this);
            b3.add(jb);
            b3.add(Box.createVerticalStrut(50));

            pan.add(b3);
            con.add(pan);
            setVisible(true);

        }

        public static void main(String args[]) {
            rjgc main = new rjgc();
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource() == jb) {
                jf1.setText("");
                jf2.setText("");
                jf3.setText("");
                jf4.setText("");
                jl1.setText("?");
                jl2.setText("?");
                jl6.setText("?");
                jl9.setText("?");
                jl21.setText("0");
                jl22.setText("0");
                jl23.setText("0");
                jl24.setText("0");
                jl25.setText("0");
                jl26.setText("0");
                jl27.setText("0");
                jl28.setText("0");
                jl29.setText("0");
                jl210.setText("0");
                jl211.setText("0");
                jl212.setText("0");
                jl213.setText("0");
                jl214.setText("0");
                jl215.setText("0");
            }
            if (e.getSource() == jb1) {
                jf3.setText("");
                jf4.setText("");
                jl1.setText("?");
                jl2.setText("?");
                jl6.setText("?");
                jl9.setText("?");
                Random rand = new Random();
                int i = rand.nextInt(100);
                int j = rand.nextInt(100);
                i = i + 1;
                j = j + 1;
                if (i < j) {
                    String s = Integer.toString(i);
                    String y = Integer.toString(j);

                    jf1.setText(y);
                    jf2.setText(s);
                } else {
                    String s = Integer.toString(i);
                    String y = Integer.toString(j);
                    jf1.setText(s);
                    jf2.setText(y);
                }
                int f = rand.nextInt();
                f = rand.nextInt(4);
                if (f == 0) {
                    jl2.setText("+");
                } else if (f == 1) {
                    jl2.setText("-");
                } else if (f == 2) {
                    jl2.setText("*");
                } else if (f == 3) {
                    jl2.setText("/");
                }
            }
            if (e.getSource() == jb5) {
                int b, c, d, f, h, g, k, l, m, n, o, p;
                int r, t, u;
                r = Integer.parseInt(jl213.getText()) + 1;
                jl213.setText(Integer.toString(r));
                jl1.setText("?");
                int x, y, answer = 0;
                String z, i, j, s = null;
                x = Integer.parseInt(jf1.getText());
                y = Integer.parseInt(jf2.getText());
                z = jl2.getText();
                i = jf3.getText();
                j = jf4.getText();
                if (z == "+") {
                    b = Integer.parseInt(jl21.getText()) + 1;
                    jl21.setText(Integer.toString(b));
                    answer = x + y;
                } else if (z == "-") {
                    f = Integer.parseInt(jl24.getText()) + 1;
                    jl24.setText(Integer.toString(f));
                    answer = x - y;
                } else if (z == "*") {
                    k = Integer.parseInt(jl27.getText()) + 1;
                    jl27.setText(Integer.toString(k));
                    answer = x * y;
                } else if (z == "/") {
                    n = Integer.parseInt(jl210.getText()) + 1;
                    jl210.setText(Integer.toString(n));
                    answer = x / y;
                    jl1.setText("0");
                    if (x % y != 0) {
                        s = Integer.toString(x % y);
                        jl1.setText(s);
                    }
                }
                String a = Integer.toString(answer);
                jl6.setText(a);
                if (i.equals(a)) {
                    if (s == null) {
                        jl9.setText("对");
                        t = Integer.parseInt(jl214.getText()) + 1;
                        jl214.setText(Integer.toString(t));
                        if (z == "+") {
                            c = Integer.parseInt(jl22.getText()) + 1;
                            jl22.setText(Integer.toString(c));
                        } else if (z == "-") {
                            h = Integer.parseInt(jl25.getText()) + 1;
                            jl25.setText(Integer.toString(h));
                        } else if (z == "*") {
                            l = Integer.parseInt(jl28.getText()) + 1;
                            jl28.setText(Integer.toString(l));
                        } else if (z == "/") {
                            o = Integer.parseInt(jl211.getText()) + 1;
                            jl211.setText(Integer.toString(o));
                        }
                    } else if (j.equals(s)) {
                        jl9.setText("对");
                        t = Integer.parseInt(jl214.getText()) + 1;
                        jl214.setText(Integer.toString(t));
                        if (z == "+") {
                            c = Integer.parseInt(jl22.getText()) + 1;
                            jl22.setText(Integer.toString(c));
                        } else if (z == "-") {
                            h = Integer.parseInt(jl25.getText()) + 1;
                            jl25.setText(Integer.toString(h));
                        } else if (z == "*") {
                            l = Integer.parseInt(jl28.getText()) + 1;
                            jl28.setText(Integer.toString(l));
                        } else if (z == "/") {
                            o = Integer.parseInt(jl211.getText()) + 1;
                            jl211.setText(Integer.toString(o));
                        }
                    } else {
                        jl9.setText("错");
                        u = Integer.parseInt(jl215.getText()) + 1;
                        jl215.setText(Integer.toString(u));
                        if (z == "+") {
                            d = Integer.parseInt(jl23.getText()) + 1;
                            jl23.setText(Integer.toString(d));
                        } else if (z == "-") {
                            g = Integer.parseInt(jl26.getText()) + 1;
                            jl26.setText(Integer.toString(g));
                        } else if (z == "*") {
                            m = Integer.parseInt(jl29.getText()) + 1;
                            jl29.setText(Integer.toString(m));
                        } else if (z == "/") {
                            p = Integer.parseInt(jl212.getText()) + 1;
                            jl212.setText(Integer.toString(p));
                        }
                    }
                } else {
                    jl9.setText("错");
                    u = Integer.parseInt(jl215.getText()) + 1;
                    jl215.setText(Integer.toString(u));
                    if (z == "+") {
                        d = Integer.parseInt(jl23.getText()) + 1;
                        jl23.setText(Integer.toString(d));
                    } else if (z == "-") {
                        g = Integer.parseInt(jl26.getText()) + 1;
                        jl26.setText(Integer.toString(g));
                    } else if (z == "*") {
                        m = Integer.parseInt(jl29.getText()) + 1;
                        jl29.setText(Integer.toString(m));
                    } else if (z == "/") {
                        p = Integer.parseInt(jl212.getText()) + 1;
                        jl212.setText(Integer.toString(p));
                    }
                }
            }
        }
    }

    程序运行界面:

    • 三人合作步骤

            1. 先对题目做一个大概的分析,明确需要做什么,并在第二次作业基础上进行交流。

            2. 通过书籍、互联网、请教老师搜集相关资料。

            3. 重新写了代码,并进行规范以及相应的修改。

            4. 对函数进行模块化,将函数进行了封装。

            5. 进行代码反复检查。

            6. 进行相应的测试,检查系统是否符合设计要求。

    • 总结

    通过第二次作业和第三次作业的演练,我组三位成员都明白了合作和明确分工是完成任务的关键,充分的认

    识到各自的优点和不足,在以后的学习中,取长补短,更好的完成下一次作业,我们得编程思想和编程能力

    得到了锻炼和提升!

    • psp耗时统计

           

    步骤

    耗时

    百分比

    理解题目要求和查找资料

    2

    4.44

    需求分析

    5

    11.12

    具体设计

    3

    6.67

    代码规范和函数封装

    3

    6.67

    代码复审

    15

    33.33

    测试

    15

    33.33

    总结

    2

    4.44

     
  • 相关阅读:
    Python--day34--socket模块的方法
    Python--day32--ftp文件传输报错的原因
    Python--day32--struct模块
    Python--day32--复习:https和http的区别;黏包;黏包问题的解决方式;
    快捷键(随时补充)
    turtle 20秒画完小猪佩奇“社会人”
    Kibana使用教程
    Elasticsearch: 权威指南
    數據可視化大屏
    newtonsoft文檔說明
  • 原文地址:https://www.cnblogs.com/yy0848/p/4448618.html
Copyright © 2020-2023  润新知