个人作业1——四则运算题目生成程序(java代码,基于控制台)

一、题目描述:

从《构建之法》第一章的 “程序” 例子出发,像阿超那样,花二十分钟写一个能自动生成小学四则运算题目的命令行 “软件”,满足以下需求:

    1. 除了整数以外,还要支持真分数的四则运算,真分数的运算,例如:1/6 + 1/8 = 7/24。
    2. 运算符为 +, −, ×, ÷。
    3. 并且要求能处理用户的输入,并判断对错,打分统计正确率。
    4. 要求能处理用户输入的真分数, 如 1/2, 5/12 等。
    5. 使用 -n 参数控制生成题目的个数,例如执行下面命令将生成10个题目。
      Myapp.exe -n 10

二、需求分析:

由题目可得代码需要实现:

  1. 自动生成小学四则运算,需要用到随机数,用随机数随机生成数字,能够随机生成符号加减乘除(除数不为0)。
  2. 支持分数和整数的四则运算,同样是利用随机数分别生成分子与分母(分母不为0).
  3. 能够判断输入答案的对错并统计正确率,要将用户输入答案与式子答案进行比较(数字用==,字符串用equals语句完成)。
  4. 要求输入的分数可以被识别,此处同样利用equals来完成。
  5. 支持命令生成。

三、实现步骤:

  1. 根据用户输入的参数生成相应数量的题目。
  2. 利用Random语句实现随机生成的整数、分子、分母以及加减乘除(对于加减乘除,我用if语句实现,0----加,1----减,2----乘,3----除)。
  3. 通过用户输入的答案与式子答案进行比较,判断对错,对的返回正确并统计,错的返回错误并附上正确答案但不统计。
  4. 将统计正确的题目数量除以用户最初输入的题目数量得到正确率并输出。

四、代码设计思路

  1. 通过随机数来实现整数以及分数(分子和分母)。
  2. 通过随机数结合if条件语句实现加减乘除四个运算符号。

五、代码

package sizeyunsuan;
import java.util.Random;
import java.util.Scanner;
public class Arithmetic {
	public static void main(String[] args){
		int x,y,z,p,g;
		int a,b,c,m,n;
		int h = 0;
		System.out.printf("请输入需要生成的题目数量:");
		Scanner d = new Scanner(System.in);
		x = d.nextInt();
		for(int i = 0 ; i < x ; i++){
			Random aa = new Random();
			Random bb = new Random();
			Random cc = new Random();
			Random mm = new Random();
			Random nn = new Random();
			a = aa.nextInt(10);
			b = bb.nextInt(10);
		    c = cc.nextInt(4);
		    m = mm.nextInt(10);
		    n = nn.nextInt(10);
			if(c==0){
				if(m==0&&n==0){
					m = mm.nextInt(10)+1;
					n = nn.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						y = a + b;
						System.out.printf(a+"+"+b+"= ");
						Scanner e1 = new Scanner(System.in);
						z = e1.nextInt();
						if(z==y){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+y);
						}
					}else if(a%m==0&&b%n!=0){
						String l = b + "/" + n;
						y = a*n + b ;
						System.out.printf(a+"+"+l+"= ");
						String k = 	y + "/"+ n;
						Scanner e6 = new Scanner(System.in);
						String j = e6.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else if(a%m!=0&&b%n==0){
						String l = a + "/" + m;
						y = a + b*m;
						System.out.printf(l+"+"+b+"= ");
						String k = 	y + "/"+ m;
						Scanner e7 = new Scanner(System.in);
						String j = e7.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else{
						String l1 = a + "/" + m;
						String l2 = b + "/" + n;
						y = a*n + b*m; 
						System.out.printf(l1+"+"+l2+"= ");
						String k = 	y + "/"+ n*m;
						Scanner e8 = new Scanner(System.in);
						String j = e8.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}
				}else if(m==0&&n!=0){
					m = mm.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						y = a + b;
						System.out.printf(a+"+"+b+"= ");
						Scanner e1 = new Scanner(System.in);
						z = e1.nextInt();
						if(z==y){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+y);
						}
					}else if(a%m==0&&b%n!=0){
						String l = b + "/" + n;
						y = a*n + b ;
						System.out.printf(a+"+"+l+"= ");
						String k = 	y + "/"+ n;
						Scanner e6 = new Scanner(System.in);
						String j = e6.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else if(a%m!=0&&b%n==0){
						String l = a + "/" + m;
						y = a + b*m;
						System.out.printf(l+"+"+b+"= ");
						String k = 	y + "/"+ m;
						Scanner e7 = new Scanner(System.in);
						String j = e7.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else{
						String l1 = a + "/" + m;
						String l2 = b + "/" + n;
						y = a*n + b*m; 
						System.out.printf(l1+"+"+l2+"= ");
						String k = 	y + "/"+ n*m;
						Scanner e8 = new Scanner(System.in);
						String j = e8.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}
				}else if(m!=0&&n==0){
					n = nn.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						y = a + b;
						System.out.printf(a+"+"+b+"= ");
						Scanner e1 = new Scanner(System.in);
						z = e1.nextInt();
						if(z==y){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+y);
						}
					}else if(a%m==0&&b%n!=0){
						String l = b + "/" + n;
						y = a*n + b ;
						System.out.printf(a+"+"+l+"= ");
						String k = 	y + "/"+ n;
						Scanner e6 = new Scanner(System.in);
						String j = e6.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else if(a%m!=0&&b%n==0){
						String l = a + "/" + m;
						y = a + b*m;
						System.out.printf(l+"+"+b+"= ");
						String k = 	y + "/"+ m;
						Scanner e7 = new Scanner(System.in);
						String j = e7.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else{
						String l1 = a + "/" + m;
						String l2 = b + "/" + n;
						y = a*n + b*m; 
						System.out.printf(l1+"+"+l2+"= ");
						String k = 	y + "/"+ n*m;
						Scanner e8 = new Scanner(System.in);
						String j = e8.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}
				}else{
					if(a%m==0&&b%n==0){
						y = a + b;
						System.out.printf(a+"+"+b+"= ");
						Scanner e1 = new Scanner(System.in);
						z = e1.nextInt();
						if(z==y){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+y);
						}
					}else if(a%m==0&&b%n!=0){
						String l = b + "/" + n;
						y = a*n + b ;
						System.out.printf(a+"+"+l+"= ");
						String k = 	y + "/"+ n;
						Scanner e6 = new Scanner(System.in);
						String j = e6.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else if(a%m!=0&&b%n==0){
						String l = a + "/" + m;
						y = a + b*m;
						System.out.printf(l+"+"+b+"= ");
						String k = 	y + "/"+ m;
						Scanner e7 = new Scanner(System.in);
						String j = e7.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else{
						String l1 = a + "/" + m;
						String l2 = b + "/" + n;
						y = a*n + b*m; 
						System.out.printf(l1+"+"+l2+"= ");
						String k = 	y + "/"+ n*m;
						Scanner e8 = new Scanner(System.in);
						String j = e8.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}
				}
			}
			if(c==1){
				if(m==0&&n==0){
					m = mm.nextInt(10)+1;
					n = nn.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						y = a - b;
						System.out.printf(a+"-"+b+"= ");
						Scanner e2 = new Scanner(System.in);
						z = e2.nextInt();
						if(z==y){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+y);
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*n - b ;
					System.out.printf(a+"-"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a - b*m;
					System.out.printf(l+"-"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n - b*m; 
					System.out.printf(l1+"-"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}else if(m==0&&n!=0){
				m = mm.nextInt(10)+1;
				if(a%m==0&&b%n==0){
					y = a - b;
					System.out.printf(a+"-"+b+"= ");
					Scanner e1 = new Scanner(System.in);
					z = e1.nextInt();
					if(z==y){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+y);
					}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*n - b ;
					System.out.printf(a+"-"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a - b*m;
					System.out.printf(l+"-"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n - b*m; 
					System.out.printf(l1+"-"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
			}else if(m!=0&&n==0){
				n = nn.nextInt(10)+1;
				if(a%m==0&&b%n==0){
					y = a - b;
					System.out.printf(a+"-"+b+"= ");
					Scanner e1 = new Scanner(System.in);
					z = e1.nextInt();
					if(z==y){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+y);
					}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*n - b ;
					System.out.printf(a+"-"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a - b*m;
					System.out.printf(l+"-"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n - b*m; 
					System.out.printf(l1+"-"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
			}else{
				if(a%m==0&&b%n==0){
					y = a - b;
					System.out.printf(a+"-"+b+"= ");
					Scanner e1 = new Scanner(System.in);
					z = e1.nextInt();
					if(z==y){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+y);
					}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*n - b ;
					System.out.printf(a+"-"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a - b*m;
					System.out.printf(l+"-"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n - b*m; 
					System.out.printf(l1+"-"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
			}
			}
		    if(c==2){
		    	if(m==0&&n==0){
					m = mm.nextInt(10)+1;
					n = nn.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						y = a * b;
						System.out.printf(a+"x"+b+"= ");
						Scanner e3 = new Scanner(System.in);
						z = e3.nextInt();
						if(z==y){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+y);
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*b ;
					System.out.printf(a+"x"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = b*a;
					System.out.printf(l+"x"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*b; 
					System.out.printf(l1+"x"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}else if(m==0&&n!=0){
				m = mm.nextInt(10)+1;
				if(a%m==0&&b%n==0){
					y = a * b;
					System.out.printf(a+"x"+b+"= ");
					Scanner e1 = new Scanner(System.in);
					z = e1.nextInt();
					if(z==y){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+y);
					}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*b;
					System.out.printf(a+"x"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a*b;
					System.out.printf(l+"x"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*b; 
					System.out.printf(l1+"x"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
			}else if(m!=0&&n==0){
				n = nn.nextInt(10)+1;
				if(a%m==0&&b%n==0){
					y = a * b;
					System.out.printf(a+"x"+b+"= ");
					Scanner e1 = new Scanner(System.in);
					z = e1.nextInt();
					if(z==y){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+y);
					}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*b ;
					System.out.printf(a+"x"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a*b;
					System.out.printf(l+"x"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*b; 
					System.out.printf(l1+"x"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
			}else{
				if(a%m==0&&b%n==0){
					y = a * b;
					System.out.printf(a+"x"+b+"= ");
					Scanner e1 = new Scanner(System.in);
					z = e1.nextInt();
					if(z==y){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+y);
					}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					y = a*b ;
					System.out.printf(a+"x"+l+"= ");
					String k = 	y + "/"+ n;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a*b;
					System.out.printf(l+"x"+b+"= ");
					String k = 	y + "/"+ m;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*b; 
					System.out.printf(l1+"x"+l2+"= ");
					String k = 	y + "/"+ n*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
			}
			}
			if(c==3){
				if(b==0){
					b = bb.nextInt(10)+1;
					if(m==0&&n==0){
						m = mm.nextInt(10)+1;
						n = nn.nextInt(10)+1;
						if(a%m==0&&b%n==0){
							if(a%b!=0){
								String l=a+"/"+b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e4 = new Scanner(System.in);
							String p1 = e4.next();
							if(p1.equals(l)){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+l);
							}
							}else{
								p = a / b;
								System.out.printf(a+"÷"+b+"= ");
								Scanner e5 = new Scanner(System.in);
								g = e5.nextInt();
								if(p==g){
									System.out.println("回答正确!");
									h++;
								}else{
									System.out.println("回答错误!正确答案是"+p);
								}
							}
					}else if(a%m==0&&b%n!=0){
						String l = b + "/" + n;
						if(a==0){System.out.println(a+"÷"+l+"= ");
						Scanner e6 = new Scanner(System.in);
						p = e6.nextInt();
						if(p==0){System.out.println("回答正确!");h++;
						continue;}else{System.out.println("回答错误!正确答案是0");continue;}
						}
						y = a*n ;
						System.out.printf(a+"÷"+l+"= ");
						String k = 	y + "/"+ b;
						Scanner e6 = new Scanner(System.in);
						String j = e6.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else if(a%m!=0&&b%n==0){
						String l = a + "/" + m;
						y = a;
						System.out.printf(l+"÷"+b+"= ");
						String k = 	y + "/"+ m*b;
						Scanner e7 = new Scanner(System.in);
						String j = e7.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else{
						String l1 = a + "/" + m;
						String l2 = b + "/" + n;
						y = a*n; 
						System.out.printf(l1+"÷"+l2+"= ");
						String k = 	y + "/"+ b*m;
						Scanner e8 = new Scanner(System.in);
						String j = e8.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}
					}else if(m==0&&n!=0){
					m = mm.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						if(a%b!=0){
							String l=a+"/"+b;
						System.out.printf(a+"÷"+b+"= ");
						Scanner e4 = new Scanner(System.in);
						String p1 = e4.next();
						if(p1.equals(l)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+l);
						}
						}else{
							p = a / b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e5 = new Scanner(System.in);
							g = e5.nextInt();
							if(p==g){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+p);
							}
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					if(a==0){System.out.println(a+"÷"+l+"= ");
					Scanner e6 = new Scanner(System.in);
					p = e6.nextInt();
					if(p==0){System.out.println("回答正确!");h++;
					continue;}else{System.out.println("回答错误!正确答案是0");continue;}
					}
					y = a*n ;
					System.out.printf(a+"÷"+l+"= ");
					String k = 	y + "/"+ b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a;
					System.out.printf(l+"÷"+b+"= ");
					String k = 	y + "/"+ m*b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n; 
					System.out.printf(l1+"÷"+l2+"= ");
					String k = 	y + "/"+ b*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}else if(m!=0&&n==0){
					n = nn.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						if(a%b!=0){
							String l=a+"/"+b;
						System.out.printf(a+"÷"+b+"= ");
						Scanner e4 = new Scanner(System.in);
						String p1 = e4.next();
						if(p1.equals(l)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+l);
						}
						}else{
							p = a / b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e5 = new Scanner(System.in);
							g = e5.nextInt();
							if(p==g){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+p);
							}
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					if(a==0){System.out.println(a+"÷"+l+"= ");
					Scanner e6 = new Scanner(System.in);
					p = e6.nextInt();
					if(p==0){System.out.println("回答正确!");h++;
					continue;}else{System.out.println("回答错误!正确答案是0");continue;}
					}
					y = a*n ;
					System.out.printf(a+"÷"+l+"= ");
					String k = 	y + "/"+ b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a;
					System.out.printf(l+"÷"+b+"= ");
					String k = 	y + "/"+ m*b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n; 
					System.out.printf(l1+"÷"+l2+"= ");
					String k = 	y + "/"+ b*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}else{
					if(a%m==0&&b%n==0){
						if(a%b!=0){
							String l=a+"/"+b;
						System.out.printf(a+"÷"+b+"= ");
						Scanner e4 = new Scanner(System.in);
						String p1 = e4.next();
						if(p1.equals(l)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+l);
						}
						}else{
							p = a / b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e5 = new Scanner(System.in);
							g = e5.nextInt();
							if(p==g){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+p);
							}
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					if(a==0){System.out.println(a+"÷"+l+"= ");
					Scanner e6 = new Scanner(System.in);
					p = e6.nextInt();
					if(p==0){System.out.println("回答正确!");h++;
					continue;}else{System.out.println("回答错误!正确答案是0");continue;}
					}
					y = a*n ;
					System.out.printf(a+"÷"+l+"= ");
					String k = 	y + "/"+ b;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a;
					System.out.printf(l+"÷"+b+"= ");
					String k = 	y + "/"+ m*b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n; 
					System.out.printf(l1+"÷"+l2+"= ");
					String k = 	y + "/"+ b*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}
				}else{
				//p =(float) a / b;
					if(m==0&&n==0){
						m = mm.nextInt(10)+1;
						n = nn.nextInt(10)+1;
						if(a%m==0&&b%n==0){
							if(a%b!=0){
								String l=a+"/"+b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e4 = new Scanner(System.in);
							String p1 = e4.next();
							if(p1.equals(l)){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+l);
							}
							}else{
								p = a / b;
								System.out.printf(a+"÷"+b+"= ");
								Scanner e5 = new Scanner(System.in);
								g = e5.nextInt();
								if(p==g){
									System.out.println("回答正确!");
									h++;
								}else{
									System.out.println("回答错误!正确答案是"+p);
								}
							}
					}else if(a%m==0&&b%n!=0){
						String l = b + "/" + n;
						y = a*n ;
						System.out.printf(a+"÷"+l+"= ");
						String k = 	y + "/"+ b;
						Scanner e6 = new Scanner(System.in);
						String j = e6.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else if(a%m!=0&&b%n==0){
						String l = a + "/" + m;
						if(a==0){System.out.println(a+"÷"+l+"= ");
						Scanner e6 = new Scanner(System.in);
						p = e6.nextInt();
						if(p==0){System.out.println("回答正确!");h++;
						continue;}else{System.out.println("回答错误!正确答案是0");continue;}
						}
						y = a;
						System.out.printf(l+"÷"+b+"= ");
						String k = 	y + "/"+ m*b;
						Scanner e7 = new Scanner(System.in);
						String j = e7.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}else{
						String l1 = a + "/" + m;
						String l2 = b + "/" + n;
						y = a*n; 
						System.out.printf(l1+"÷"+l2+"= ");
						String k = 	y + "/"+ b*m;
						Scanner e8 = new Scanner(System.in);
						String j = e8.next();
						if(j.equals(k)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+k);
						}
					}
					}else if(m==0&&n!=0){
					m = mm.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						if(a%b!=0){
							String l=a+"/"+b;
						System.out.printf(a+"÷"+b+"= ");
						Scanner e4 = new Scanner(System.in);
						String p1 = e4.next();
						if(p1.equals(l)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+l);
						}
						}else{
							p = a / b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e5 = new Scanner(System.in);
							g = e5.nextInt();
							if(p==g){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+p);
							}
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					if(a==0){System.out.println(a+"÷"+l+"= ");
					Scanner e6 = new Scanner(System.in);
					p = e6.nextInt();
					if(p==0){System.out.println("回答正确!");h++;
					continue;}else{System.out.println("回答错误!正确答案是0");continue;}
					}
					y = a*n ;
					System.out.printf(a+"÷"+l+"= ");
					String k = 	y + "/"+ b;
					Scanner e6 = new Scanner(System.in);
					String j = e6.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a;
					System.out.printf(l+"÷"+b+"= ");
					String k = 	y + "/"+ m*b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n; 
					System.out.printf(l1+"÷"+l2+"= ");
					String k = 	y + "/"+ b*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}else if(m!=0&&n==0){
					n = nn.nextInt(10)+1;
					if(a%m==0&&b%n==0){
						if(a%b!=0){
							String l=a+"/"+b;
						System.out.printf(a+"÷"+b+"= ");
						Scanner e4 = new Scanner(System.in);
						String p1 = e4.next();
						if(p1.equals(l)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+l);
						}
						}else{
							p = a / b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e5 = new Scanner(System.in);
							g = e5.nextInt();
							if(p==g){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+p);
							}
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					if(a==0){System.out.println(a+"÷"+l+"= ");
					Scanner e6 = new Scanner(System.in);
					p = e6.nextInt();
					if(p==0){System.out.println("回答正确!");h++;
					continue;}else{System.out.println("回答错误!正确答案是0");continue;}
					}
					y = a*n ;
					System.out.printf(a+"÷"+l+"= ");
					String k = 	y + "/"+ b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a;
					System.out.printf(l+"÷"+b+"= ");
					String k = 	y + "/"+ m*b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n; 
					System.out.printf(l1+"÷"+l2+"= ");
					String k = 	y + "/"+ b*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}else{
					if(a%m==0&&b%n==0){
						if(a%b!=0){
							String l=a+"/"+b;
						System.out.printf(a+"÷"+b+"= ");
						Scanner e4 = new Scanner(System.in);
						String p1 = e4.next();
						if(p1.equals(l)){
							System.out.println("回答正确!");
							h++;
						}else{
							System.out.println("回答错误!正确答案是"+l);
						}
						}else{
							p = a / b;
							System.out.printf(a+"÷"+b+"= ");
							Scanner e5 = new Scanner(System.in);
							g = e5.nextInt();
							if(p==g){
								System.out.println("回答正确!");
								h++;
							}else{
								System.out.println("回答错误!正确答案是"+p);
							}
						}
				}else if(a%m==0&&b%n!=0){
					String l = b + "/" + n;
					if(a==0){System.out.println(a+"÷"+l+"= ");
					Scanner e6 = new Scanner(System.in);
					p = e6.nextInt();
					if(p==0){System.out.println("回答正确!");h++;
					continue;}else{System.out.println("回答错误!正确答案是0");continue;}
					}
					y = a*n ;
					System.out.printf(a+"÷"+l+"= ");
					String k = 	y + "/"+ b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else if(a%m!=0&&b%n==0){
					String l = a + "/" + m;
					y = a;
					System.out.printf(l+"÷"+b+"= ");
					String k = 	y + "/"+ m*b;
					Scanner e7 = new Scanner(System.in);
					String j = e7.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}else{
					String l1 = a + "/" + m;
					String l2 = b + "/" + n;
					y = a*n; 
					System.out.printf(l1+"÷"+l2+"= ");
					String k = 	y + "/"+ b*m;
					Scanner e8 = new Scanner(System.in);
					String j = e8.next();
					if(j.equals(k)){
						System.out.println("回答正确!");
						h++;
					}else{
						System.out.println("回答错误!正确答案是"+k);
					}
				}
				}
			    }
		    }
		}
		System.out.println("总共"+x+"题,"+"恭喜答对"+h+"题");
		System.out.println("正确率为"+(float)h/x);
	}
}

六、测试

PSP:

Personal Software Process Stages

Time (m) Senior

Student

Time (m)

计划

10 15
估计这个任务需要多少时间 10 8
开发 100 60
需求分析(包括学习新技术) 5 3
生成设计文档 0 0
设计复审 0 0
代码规范 20 30
具体设计 10 15
具体编码 120 150
代码复审 10 8
测试(自我测试,修改代码,提交修改) 20 40
报告 30 50
测试报告 5 3
计算工作量 5 3
并提出过程修改计划 5 5

 

Coding码市地址:

https://git.coding.net/w934707136/Arithmetic.git 

posted @ 2017-03-07 19:59  王大节  阅读(1688)  评论(1编辑  收藏  举报