初学java实现部分加法测试

import java.util.Scanner;
public class test_4{
    public static void main(String arg[]) {	
	welcome();
	int m=0,n=0;
	int a[]=start();
	int[] b={0,0};
	Plus1 p1= new Plus1();
	Plus2 p2= new Plus2();
	Plus3 p3= new Plus3();
	Plus4 p4= new Plus4();
	for(int i = 0;i < a[1]; i++){
		if(a[0]==1){
			b=p1.run(a[2]);
			}
		else if(a[0]==2){
			b=p2.run(a[2]);				
			}
		else if(a[0]==3){
			b=p3.run(a[2]);				
			}
		else if(a[0]==4){
			b=p4.run(a[2]);				
			}
		else{
			System.exit(0);
		}
		m=m+b[1];
		n=n+b[0];
		}
	End(m,n);
	}
	
	public static void welcome(){
	System.out.println("\n\n\n\t\t\t /\\/\\欢迎使用/\\/\\\n\n");
	System.out.println("\t*1.两位数和为两位数加法\t\t*2.两位小数和为两位小数加法\n\t*3.两位数和不确定加法\t\t*4.两位小数和不确定加法\n");
	}
	
	public static int[] start(){
	Scanner sc=new Scanner(System.in);
	System.out.print("\t\t\t*请选择您要练习的题型:");
	int l=sc.nextInt();
	if(l > 4){
		System.out.println("\n\t\t\t*无此题型,请重新输入\n");
		return start();
	}
	System.out.print("\n\t\t\t*输入练习题数:");
	int m=sc.nextInt();
	System.out.print("\n\t\t\t*输入练习次数:");
	int n=sc.nextInt();
	int[] array={l,m,n};
	return array;
	}
	
	public static void End(int m,int n){
	System.out.println("\n\t计算成绩中");
	System.out.print("\t");
	System.out.print("[");
	for(int i=0;i<10;i++){
	System.out.print("▋");
	try { Thread.sleep (100) ;
		} catch (InterruptedException ie){}
	}
	System.out.print("]");
	System.out.println("\n\t计算完成");
	System.out.println("\n\t你的最终得分为"+m+"第一次做对题数"+n);
	}
}

class Plus1{
public static float[] draw(){
	float Max=1,Min=0;
	float c,d;
	c=(int)(Math.random()*(100-10))+10;
	d=(int)(Math.random()*(100-10))+10;
	if(c + d > 100){
		return draw();
	}
	float[] array={c,d};
	return array;
	}
	
	public static int[] run(int n){
	float[] a=draw();
	int c=1;
	System.out.println("\n\t"+a[0]+"+"+a[1]+"=");
	Scanner sc=new Scanner(System.in);
	for(int i=0;i<n;i++){
	System.out.print("\t请输入答案");
		float b=sc.nextFloat();
		if(b==a[0]+a[1]){
			w();
			if(c==1){
				int[] array={1,1};
				return array;
				}
			else{
				int[] array={0,1};
				return array;
				}
			}
		else{
			if(i!=(n-1))
				g();
				c=c-1;
			}
		}
		f();
		int[] array={0,0};
		return array;
	}
	
	public static void w(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t恭喜你答对了");
			break;
		case 1:
			System.out.println("\t恭喜恭喜");
			break;
		case 2:
			System.out.println("\t很好,下次继续加油");
			break;
		}
	}
	
	public static void g(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t不要放弃");
			break;
		case 1:
			System.out.println("\t加油");
			break;
		case 2:
			System.out.println("\t别灰心,再来一次");
			break;
		}
	}
	
	public static void f(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\tThe end");
			break;
		case 1:
			System.out.println("\t继续努力");
			break;
		case 2:
			System.out.println("\t相信自己能行");
			break;
		}
	}
}

class Plus2{
public static float[] draw(){
	float Max=1,Min=0;
	float c,d;
	c=(float)(Math.round((Math.random()*(Max-Min)+Min)*100))/100;
	d=(float)(Math.round((Math.random()*(Max-Min)+Min)*100))/100;
	if(c + d > 1){
		return draw();
	}
	float[] array={c,d};
	return array;
	}
	
	public static int[] run(int n){
	float[] a=draw();
	int c=1;
	System.out.println("\n\t"+a[0]+"+"+a[1]+"=");
	Scanner sc=new Scanner(System.in);
	for(int i=0;i<n;i++){
	System.out.print("\t请输入答案");
		float b=sc.nextFloat();
		if(b==a[0]+a[1]){
			w();
			if(c==1){
				int[] array={1,1};
				return array;
				}
			else{
				int[] array={0,1};
				return array;
				}
			}
		else{
			if(i!=(n-1))
				g();
				c=c-1;
			}
		}
		f();
		int[] array={0,0};
		return array;
	}
	
	public static void w(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t恭喜你答对了");
			break;
		case 1:
			System.out.println("\t恭喜恭喜");
			break;
		case 2:
			System.out.println("\t很好,下次继续加油");
			break;
		}
	}
	
	public static void g(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t不要放弃");
			break;
		case 1:
			System.out.println("\t加油");
			break;
		case 2:
			System.out.println("\t别灰心,再来一次");
			break;
		}
	}
	
	public static void f(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\tThe end");
			break;
		case 1:
			System.out.println("\t继续努力");
			break;
		case 2:
			System.out.println("\t相信自己能行");
			break;
		}
	}	
}

class Plus3{
public static float[] draw(){
	float Max=1,Min=0;
	float c,d;
	c=(int)(Math.random()*(100-10))+10;
	d=(int)(Math.random()*(100-10))+10;
	float[] array={c,d};
	return array;
	}
	
	public static int[] run(int n){
	float[] a=draw();
	int c=1;
	System.out.println("\n\t"+a[0]+"+"+a[1]+"=");
	Scanner sc=new Scanner(System.in);
	for(int i=0;i<n;i++){
	System.out.print("\t请输入答案");
		float b=sc.nextFloat();
		if(b==a[0]+a[1]){
			w();
			if(c==1){
				int[] array={1,1};
				return array;
				}
			else{
				int[] array={0,1};
				return array;
				}
			}
		else{
			if(i!=(n-1))
				g();
				c=c-1;
			}
		}
		f();
		int[] array={0,0};
		return array;
	}
	
	public static void w(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t恭喜你答对了");
			break;
		case 1:
			System.out.println("\t恭喜恭喜");
			break;
		case 2:
			System.out.println("\t很好,下次继续加油");
			break;
		}
	}
	
	public static void g(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t不要放弃");
			break;
		case 1:
			System.out.println("\t加油");
			break;
		case 2:
			System.out.println("\t别灰心,再来一次");
			break;
		}
	}
	
	public static void f(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\tThe end");
			break;
		case 1:
			System.out.println("\t继续努力");
			break;
		case 2:
			System.out.println("\t相信自己能行");
			break;
		}
	}
}

class Plus4{
public static float[] draw(){
	float Max=1,Min=0;
	float c,d;
	c=(float)(Math.round((Math.random()*(Max-Min)+Min)*100))/100;
	d=(float)(Math.round((Math.random()*(Max-Min)+Min)*100))/100;
	float[] array={c,d};
	return array;
	}
	
	public static int[] run(int n){
	float[] a=draw();
	int c=1;
	System.out.println("\n\t"+a[0]+"+"+a[1]+"=");
	Scanner sc=new Scanner(System.in);
	for(int i=0;i<n;i++){
	System.out.print("\t请输入答案");
		float b=sc.nextFloat();
		if(b==a[0]+a[1]){
			w();
			if(c==1){
				int[] array={1,1};
				return array;
				}
			else{
				int[] array={0,1};
				return array;
				}
			}
		else{
			if(i!=(n-1))
				g();
				c=c-1;
			}
		}
		f();
		int[] array={0,0};
		return array;
	}
	
	public static void w(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t恭喜你答对了");
			break;
		case 1:
			System.out.println("\t恭喜恭喜");
			break;
		case 2:
			System.out.println("\t很好,下次继续加油");
			break;
		}
	}
	
	public static void g(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\t不要放弃");
			break;
		case 1:
			System.out.println("\t加油");
			break;
		case 2:
			System.out.println("\t别灰心,再来一次");
			break;
		}
	}
	
	public static void f(){
	int a=(int)(Math.random()*3);
	switch(a){
		case 0:
			System.out.println("\tThe end");
			break;
		case 1:
			System.out.println("\t继续努力");
			break;
		case 2:
			System.out.println("\t相信自己能行");
			break;
		}
	}	
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

扬志九洲

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值