动手动脑 1:通过JDK中的System.out.println()方法来理解函数重载
借此可以看到,println对应了每一种基本类型都进行了一次重载。
重载至少需要其参数类型或个数有所变化才能进行重载及调用。
今天竟然只有一个动手动脑欸,那接下来就是二柱子的故事了,题目要求如下:
阶段1: 1 定义方法验证题目是否重复;并将出题参数用方法定义。 2 定义随机数生成器方法,根据出题参数(出题个数、操作数的个数、确定操作数的取值范围)生成全部的随机操作数。
阶段2: 1 定义方法实现在线答题;全部完成后,显示答题结果,输出正确率和错题。 2 定义方法实现错题集、错题重练并记录错题的次数功能。
阶段3: 增加倒计时功能,完成定时测试功能。
今日源码:
public class Totenfour { @SuppressWarnings("resource") public static void main(String[] args) { Random rand = new Random(); int numT,numU=0,max=10,min=99; int choice=0; int[] cp=new int[100]; int[] cd=new int[100]; int[] keka=new int[100]; boolean[] pp=new boolean[100]; int answer=0; int pop=0,poe=0; int[] happy=new int[100]; int[] opea=new int[100]; Scanner in=new Scanner(System.in); System.out.print("请输入题目数"); numT=in.nextInt(); System.out.print("请输入最大值"); max=in.nextInt(); System.out.print("请输入最小值"); min=in.nextInt(); randomSet(cp,cd,numT,numU,max,min); for(int i=0;i<numT;i++) { System.out.print("第"+(i+1)+"题 "); choice=rand.nextInt(4); switch(choice) { case 0: opea[i]=0; keka[i]=cp[i]+cd[i]; System.out.print(cp[i]+"+"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; case 1: opea[i]=1; keka[i]=cp[i]-cd[i]; System.out.print(cp[i]+"-"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; case 2: opea[i]=2; keka[i]=cp[i]*cd[i]; System.out.print(cp[i]+"x"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; case 3: opea[i]=3; keka[i]=cp[i][i]; System.out.print(cp[i]+"/"+cd[i]+"="); answer=in.nextInt(); if(answer==keka[i]){pp[i]=true;} else {pp[i]=false;happy[poe]=i;poe++;} break; } } pop=curry(pp,numT); for(;pop!=1;) { int k=poe; System.out.println("这里还有错题哦,一共"+poe+"道题目"); for(int i=0;i<k;i++) { switch(opea[happy[i]]) { case 0: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]]+cd[happy[i]]; System.out.print(cp[happy[i]]+"+"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; case 1: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]]-cd[happy[i]]; System.out.print(cp[happy[i]]+"-"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; case 2: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]]*cd[happy[i]]; System.out.print(cp[happy[i]]+"x"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; case 3: System.out.print("第"+(happy[i]+1)+"题 "); keka[happy[i]]=cp[happy[i]][happy[i]]; System.out.print(cp[happy[i]]+"/"+cd[happy[i]]+"="); answer=in.nextInt(); if(answer==keka[happy[i]]){pp[happy[i]]=true;poe--;} break; } } pop=curry(pp,numT); } System.out.println("恭喜,全部正确啦"); in.close(); } public static int curry(boolean[] i,int numT) { for(int c=0;c<numT;c++) { if(i[c]==false) { return 0; } } return 1; } public static int check(int[] kp,int [] kk,int i,int s) { for(int k=0;k<=50;k++) { if((kk[k]==i)&&(kp[k]==s)) {return 0;} } return 1; } public static void randomSet(int a[],int b[],int numT,int numU ,int max,int min) { Random rand = new Random(); int r;int p; for(int x=0;x<numT;x++) { r=rand.nextInt(max-min+1) + min; p=rand.nextInt(max-min+1) + min; int op=check(a,b,r,p); for(;op!=1;) { r=rand.nextInt(max-min+1) + min; p=rand.nextInt(max-min+1) + min; op=check(a,b,r,p); } a[x]=r;b[x]=p; } } }
运行结果如下: