标签:查找 用户 统计 uml inf void 思维 and pre
Random ran = new Random();
随机数方法创建对象int B = ran.nextInt(2);
生成0—1之内的随机数能多次生成题目
uml图:
public class Calculate {
public static void main(String[] args) {
NumberFormat number = NumberFormat.getPercentInstance();
Random ran = new Random();
Scanner scan = new Scanner(System.in);
while (true) {
System.out.print("请输入您所需要生成的题目数量:");
int A = scan.nextInt(); //A:题目数量
for (int i = 0; i < A; i++) {
int B = ran.nextInt(2); //生成随机数0/1,随机挑选整数或分数运算
int C = ran.nextInt(4); //生成随机数0-3,随机挑选4种运算符
IntNumber in1 = IntNumber.obj(); //整数运算
IntNumber in2 = IntNumber.obj();
Fraction score1 = Fraction.obj(); //分数运算
Fraction score2 = Fraction.obj();
if (B == 0) {
switch (C) { //整数加减乘除运算
case 0:
int num = in1.add(in2);
String num1 = "" + num;
int n = scan.nextInt();
Judgement.judge(n == num, num1);
break;
case 1:
num = in1.subtract(in2);
num1 = "" + num;
n = scan.nextInt();
Judgement.judge(n == num, num1);
break;
case 2:
num = in1.multiply(in2);
num1 = "" + num;
n = scan.nextInt();
Judgement.judge(n == num, num1);
break;
case 3:
num1 = in1.divide(score1);
String Q = scan.next();
Judgement.judge(Q.equals(num1), num1);
break;
}
} else {
switch (C) { //分数加减乘除运算
case 0:
Fraction num2 = score1.add(score2);
String num1 = num2.toString();
String s = scan.next();
Judgement.judge(s.equals(num1), num1);
break;
case 1:
num2 = score1.subtract(score2);
num1 = num2.toString();
s = scan.next();
Judgement.judge(s.equals(num1), num1);
break;
case 2:
num2 = score1.multiply(score2);
num1 = num2.toString();
s = scan.next();
Judgement.judge(s.equals(num1), num1);
break;
case 3:
num2 = score1.divide(score2);
num1 = num2.toString();
s = scan.next();
Judgement.judge(s.equals(num1), num1);
break;
}
}
}
这次结队学习任务虽然对我们来说难度大了点,但是锻炼了我们的思维。通过一个项目也更有利于积极主动地去查找学习一些知识。
时间没有认真统计,代码我们没有自己编写出来。我感觉结对学习最大的好处就是可以随时随地讨论起来,利用零散的时间也能一起学习。等啥时候我们自己能编写一个项目了大概也能画出漂亮的时间表吧0-0
标签:查找 用户 统计 uml inf void 思维 and pre
原文地址:https://www.cnblogs.com/wangyaojia/p/8849649.html