标签:can tin 加法 print int() 减法 代码 mat loading
四则运算 |
实际花费时间 |
估计花费时间 |
计划 |
8 |
6 |
明确需求和其他相关因素,估计每个阶段的时间成本 |
10 |
6 |
开发 |
82 |
88 |
|
8 |
10 |
|
5 |
6 |
|
5 |
6 |
|
3 |
3 |
|
12 |
12 |
|
32 |
21 |
|
5 |
9 |
|
12 |
21 |
报告 |
8 |
6 |
|
3 |
2 |
|
2 |
1 |
|
3 |
3 |
一,计划
随机产生加减乘除运算题,至于几道题和什么运算由用户自己进行选择
二,开发
需求分析:给小学生出题,减少家长负担
代码规范:注意编码规范
具体设计:加减乘除分为四部分,用户选择哪部分的题型,并且可以选择有多少道题
三,具体编码如下:
package operations;
import java.util.Scanner;
public class example {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
while (true){
int x, y, z;
System.out.println("****欢迎使用口算练习系统****");
System.out.println("1、加法练习");
System.out.println("2、减法练习");
System.out.println("3、乘法练习");
System.out.println("4、除法练习");
System.out.print("请选择需要练习的序号:");
z = sc.nextInt();
System.out.print("请选择需要练习的次数:");
int count = sc.nextInt();
if (z == 1){
System.out.print("您选择了加法练习");
while(count != 0 ){
System.out.println("当前剩余练习次数:" + count);
x = (int) (Math.random() * 50);
y = (int) (Math.random() * 50);
System.out.print(x + "+" + y + "=");
int result = sc.nextInt();
if (result != (x + y)){
System.out.println("回答错误,正确答案:" + (x + y));
}else {
System.out.println("回答正确");
}
count--;
}
}else if (z == 2){
System.out.print("您选择了减法练习");
while (count != 0){
System.out.println("当前剩余练习次数:" + count);
x = (int) (Math.random() * 100);
y = (int) (Math.random() * 100);
while(y > x){
x = (int) (Math.random() * 100);
}
System.out.print(x + "-" + y + "=");
int result = sc.nextInt();
if (result != (x - y)){
System.out.println("回答错误,正确答案:" + (x - y));
}else {
System.out.println("回答正确");
}
count--;
}
}else if (z == 4){
System.out.println("您选择了除法练习");
while (count != 0){
System.out.println("当前剩余练习次数:" + count );
x = (int) (Math.random() * 100);
y = (int) (Math.random() * 10);
if (y == 0){
y = (int) (Math.random() * 10);
}
System.out.print(x + " / " + y + "=");
System.out.println();
System.out.println();
/*String remove = String.valueOf((Integer)(x / y));*/
/*String more = String.valueOf((Integer) (x % y));*/
int remove = x / y;
int more = x % y;
String s;
Double DoubleResult = null;
int result = 0;
if (more == 0){
s = String.valueOf(remove);
result = sc.nextInt();
}else {
s = remove + "." + more;
DoubleResult = sc.nextDouble();
}
String StrResult = result + "";
String StrDoubleResult = DoubleResult + "";
/*System.out.println("result:" + result);
System.out.println("s:" + s);
System.out.println("remove:" + remove);
System.out.println("more:" + more);*/
if (s.equals(StrResult)){
System.out.println("回答正确");
}else if (s.equals(StrDoubleResult)){
System.out.println("回答正确");
}else {
System.out.println("回答错误,正确答案:" + s);
}
count--;
}
}else if (z == 3){
System.out.print("您选择了乘法练习");
while (count != 0){
System.out.println("当前剩余练习次数:" + count);
x = (int) (Math.random() * 10);
y = (int) (Math.random() * 10);
System.out.print(x + " x " + y + "=");
int result = sc.nextInt();
if (result != (x * y)){
System.out.println("回答错误,正确答案:" + (x * y));
}else {
System.out.println("回答正确");
}
count--;
}
}else {
System.out.println("您选择的序号有误或非法,请重新输入!!!! ");
}
}
}
}
标签:can tin 加法 print int() 减法 代码 mat loading
原文地址:https://www.cnblogs.com/hnzj-jy192-/p/14828799.html