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;
}
}
}
初学java实现部分加法测试
最新推荐文章于 2022-10-19 00:32:43 发布