20194682 automatically generates four arithmetic problem first edition report

☆ questions asked

(1) automatically generates four arithmetic operation of Equation 2 number less than 10 100 (+ - * /), operation results are required within 100

(2) discarding duplicates equation. = 2 + 3 + 3 = 2 and Equation 2 is repeated and 3 + = 3 + 2 = not repeated formula

Number (3) title can be customized

(4) parameters can be controlled

      是否包含乘法和除法

      操作数数值范围可控(如操作数 在100以内   还是1000以内)

      操作数是否含负数    

(5) generating operation to an external file title stored in result.txt

First, the needs analysis

为减轻老师的教学负担,以及方便学生的自我练习,提高学生整体成绩,特推出此款软件来自动编写四则运算小学题目。

Second, the functional design

1, the basic functions:

    (1)自动生成10道100以内的2个操作数的四则运算算式    
    (2)符号可随机生成

2, extensions

    (1)可以生成(+ - *  /)随机符号
    (2)剔除重复算式
    (3)可以用户输入生成题目数量
    (4)用户可选择是否包含乘除
    (5)用户选择题目范围,包括100以内以及1000以内
    (6)用户选择是否允许出现负数
    (7)用户选择是否保存到文件中

Third, the design and implementation

1, the use of language

    (1)java语言,版本jdk1.8

2, development tools

    (2)eclipse

3, action type and use

    (1)Scanner类:用于用户输入输出
    (2)Random类:用于随机生成数
    (3)FileWriter类:用于存储文件

4, designed to function

    (1)inputCount函数:用户输入打印个数
    (2)opCount函数:用户判断是否存在乘除
    (3)select100or1000函数:用户选择题目范围
    (4)ifFuShu函数:用户选择是否存在负数
    (5)ifSave函数:用户选择是否存到文件内
    (6)menu函数:用户界面,菜单
    (7)optt函数:实现随机生成并打印算式

Fourth, the test run



V. code shows


public void optt(int n, int opn, int sel, boolean flag, boolean ifSave) {// 通过参数控制功能
        // TODO Auto-generated method stub
        for (int i = 0; i < n; i++) {
            num1 = r.nextInt(sel) + 1;// 随机生成num1
            op = r.nextInt(opn);
            switch (op) {
            case 0:
                num2 = r.nextInt(sel - num1);
                break;
            case 1:
                num2 = r.nextInt(num1);
                break;
            case 2:
                num2 = r.nextInt(sel / num1);
                break;
            case 3:
                num2 = r.nextInt(num1);
                break;
            }

            if (flag) {
                int f = r.nextInt(2);
                int p = r.nextInt(2);
                if (0 == f)
                    num1 = -num1;
                if (0 == p)
                    num2 = -num2;
            }
            if (num1 < 0)
                str1 = "(" + num1 + ")";
            else
                str1 = "" + num1;
            if (num2 < 0)
                str2 = "(" + num2 + ")";
            else
                str2 = "" + num2;
            if (ifSave) {
                w.append(str1 + "" + opt[op] + str2 + "=" + "   ");

                try {
                    FileWriter fw = new FileWriter("d:/result.txt");
                    fw.write(w.toString());
                    fw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            System.out.println(str1 + "" + opt[op] + str2 + "=");
        }
        
    }
    public int inputCount() {// 输入打印个数
        int n;//
        n = S.nextInt();
        return n;
    }

    public int opCount() {// 判断是否有乘除;1有,其他没有
        int opn;
        opn = S.nextInt();
        if (1 == opn)
            return 4;
        else
            return 2;
    }
    public int select100or1000() {// 选择一百以内的还是一千以内的
        int sel;
        sel = S.nextInt();
        if (1 == sel)
            return 101;
        else
            return 1001;
    }
    public boolean ifFuShu() {// 判断是否有负数 1有 其他没有
        int flag;
        flag = S.nextInt();
        if (1 == flag)
            return true;
        else
            return false;
    }
    public boolean ifSave() {// 是否存储存
        int flag;
        flag = S.nextInt();
        if (1 == flag)
            return true;
        else
            return false;
    }

VI Summary

    使用面向对象程序设计,其中分为,计算类,符号类,运算符类,菜单打印类,实现模块化程序设计。但由于技术有限,只能将类转化为方法,使用。这样也可以实现模块化,避免代码的重复使用。

Seven, PSP

Guess you like

Origin www.cnblogs.com/laxla/p/11521442.html