本次作业的要求来自于: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.1 |
Personal Software Process Stages |
Time Senior Student |
Time |
Planning |
计划 |
8 |
6 |
· Estimate |
估计这个任务需要多少时间 |
8 |
6 |
Development |
开发 |
99 |
90 |
· Analysis |
需求分析 (包括学习新技术) |
6 |
10 |
· Design Spec |
生成设计文档 |
5 |
6 |
· Design Review |
设计复审 |
4 |
6 |
· Coding Standard |
代码规范 |
3 |
3 |
· Design |
具体设计 |
10 |
12 |
· Coding |
具体编码 |
36 |
21 |
· Code Review |
代码复审 |
7 |
9 |
· Test |
测试(自我测试,修改代码,提交修改) |
5 |
4 |
Reporting |
报告 |
9 |
6 |
· |
测试报告 |
3 |
2 |
· |
计算工作量 |
2 |
1 |
· |
并提出过程改进计划
|
优质内容筛选与推荐>>
1、Gang of Four 总结出的设计模式2、JavaScript开发规范要求(转载)3、LintCode "Remove Node in Binary Search Tree"4、在Windows程序中启用console输出-2016.01.045、CocoaPods简介
长按二维码向我转账
受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。