第四次作业:个人项目-小学四则运算 “软件”之初版

本次作业的要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2186

本次作业代码的github地址:https://github.com/FreyjaFs/operation.git

 

第一部分:设计思路

  • 首先很容易想到四则运算是由数字和运算符组成,设置一个二维数组存储题号及相应的运算符与数字。数字和运算符分别用数组存储,然后读取用valueof方法直接计算出答案。

第二部分:详细要求

1) 要求能出和真分数 (二分之一, 十二分之五,等)相关的练习题。

2) 并且要求能处理用户的输入,并判断对错,打分统计。 要求能处理用户输入的真分数, 如 1/2, 5/12 等

 

第三部分:主要设计

开发工具:idea

编程语言:java

主要分为三大板块:

(1)主函数

(2)生成数字和符号

(3)生成答案

(4)反馈模块

 

 

第四部分:主要设计

 

 public static void ramNum() {
        for (int jnum = 0; jnum < 3; jnum++) {
            int randomNum = (int) (1 + Math.random() * 100);
            number[jnum] = randomNum;
        }
        for (int jop = 0; jop < 2; jop++) {
            int randomop = (int) (Math.random() * 4);
            operate[jop] = randomop;
        }
    }
    //随机生成符号
    public static String radomOs(int rOs) {
        if (rOs== 0) {
            return "+";
        }
        if (rOs == 1) {
            return "-";
        }
        if (rOs == 2) {
            return "*";
        }
        if (rOs == 3) {
            return "/";
        }
        return "";
    }
    //四则运算。
    public static double operation(int opNum, double a, double b) {
        if (opNum == 0) {
            return a + b;
        }
        if (opNum == 1) {
            return a - b;
        }
        if (opNum == 2) {
            return a * b;
        }
        if (opNum == 3) {
            return a / b;
        }
        return 0;
    }
    //得出运算结果。
    public static double getResult() {
        //利用valueOf方法直接计算式子
        if (operate[1] < 2) {
            double result = operation(operate[0], number[0], number[1]);
            result = operation(operate[1], result, number[2]);
            result=Double.valueOf(result);
            return result;

        }
        else {
            double result = operation(operate[1], number[1], number[2]);
            result = operation(operate[0], number[0], result);
            result=Double.valueOf(result);
            return result;
        }
    }
    //生成题目
    public static void inttopic(int  Onum){
        double score=0;
        for(int i=0;i< Onum;i++){
            int cnum=i+1;
            ramNum();
            for (int jnum = 0; jnum < 3; jnum++) {
                //topic[i][j]i为题号,j储存题目
                topic[i][2 * jnum] = String.valueOf(number[jnum]);
            }
            for (int jop = 0; jop < 2; jop++) {
                topic[i][2 * jop + 1] = radomOs(operate[jop]);
            }
            topic[i][5] = "=";
            //
            topic[i][6] = String.valueOf(getResult());

            if(getResult()>0) {
                int j = 0;
                System.out.print("("+cnum+")");
                for (j = 0; j < 5; j++) {
                    System.out.print(topic[i][j]);
                }
                System.out.print(topic[i][5]);
                Scanner in = new Scanner(System.in);
                double inputNum = in.nextDouble();
                if (!topic[i][6].equals(String.valueOf(inputNum))) {
                    System.out.println("答错了!");
                } else {
                    score =score +100 / Onum ;
                }
            }else {i--;}
        }
        System.out.println("您的总分是"+score+"分。(每小题"+ (100/Onum)+"分,总分100分)");
        }

 运行截图

 

 

第五部分:时间预计

 

 

 

PSP2.1Personal Software Process StagesTime Senior StudentTime
Planning计划86
· Estimate估计这个任务需要多少时间86
Development开发9990
· Analysis需求分析 (包括学习新技术)610
· Design Spec生成设计文档56
· Design Review设计复审46
· Coding Standard代码规范33
· Design具体设计1012
· Coding具体编码3621
· Code Review代码复审79
· Test测试(自我测试,修改代码,提交修改)54
Reporting报告96
·测试报告32
·计算工作量21
·并提出过程改进计划

转载于:https://www.cnblogs.com/FreyjaFs/p/9608316.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值