四则运算继承篇
(1)题目要求
1.定义主界面菜单
参数设置
小学二年级口算题
小学三年级口算题
小学四年级口算题
错题集
2.其中参数设置包括出题个数(缺省值为30)、操作数数值范围。
3.小学二年级口算题操作数为两个、可进行加减乘除运算(除法必须可以整除),操作数范围不超过100.
4.小学三年级口算题操作数不超过4个,可以进行加减乘除,操作数范围不超过1000.(要求采用继承小学二年级出题类的方式,实现小学三年级的出题类)
5.小学四年级口算题操作数不超过5个,可以进行加减乘除,还可以加入括号运算。 (要求采用继承小学三年级出题类的方式,实现小学四年级的出题类)
6.学生实时答题结束后,可以选择是否进行下一套题目答题,如果选择是,则抽取下一套题进行答题,答题结束可以通过查看错题本,查询今日做题正确率。也可以针对错题进行二次答题。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 | //主方法类 package ceshi; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println( "1.参数设置" ); System.out.println( "2.小学二年级口算题" ); System.out.println( "3.小学三年级口算题" ); System.out.println( "4.小学四年级口算题" ); System.out.println( "5.退出" ); while ( true ) { System.out.println( "请输入你的选择:" ); int a=sc.nextInt(); switch (a) { case 1 :{ break ; } case 2 :{ er e= new er(); e.chuti(); System.out.println( "请输入:0.退出 1.继续答题 2.查看错题" ); int b=sc.nextInt(); if (b== 0 ) System.exit( 0 ); if (b== 2 ) {e.chongzuo();System.exit( 0 );} break ; } case 3 :{ san s= new san(); s.chuti(); System.out.println( "请输入:0.退出 1.继续答题 2.查看错题" ); int b=sc.nextInt(); if (b== 0 ) System.exit( 0 ); if (b== 2 ) {s.chongzuo();System.exit( 0 );} break ; } case 4 :{ si s= new si(); s.chuti(); System.out.println( "请输入:0.退出 1.继续答题 2.查看错题" ); int b=sc.nextInt(); if (b== 0 ) System.exit( 0 ); if (b== 2 ) {s.chongzuo();System.exit( 0 );} break ; } case 5 :System.exit( 0 ); } } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | //三年级类 package ceshi; import java.util.Random; public class san extends er{ int sumoperate; public int getSumoperate() { return sumoperate; } public void setSumoperate( int sumoperate) { this .sumoperate = sumoperate; } public void problem( int min, int max, int sumoperate, int chengchu) { Random r= new Random(); int a=r.nextInt(max+ 1 )+min; int b=r.nextInt(max+ 1 )+min; char c=fuHao(); String str= "" +a+c+b; int []cunshu = new int [ 1000 ]; char []cunfuhao = new char [ 1000 ]; int shu= 0 ; int fuhao= 0 ; if (c== '*' ) { cunshu[shu]=a*b; } else if (c== '/' ) { cunshu[shu]=a/b; } else { cunshu[shu]=a; shu++; cunshu[shu]=b; cunfuhao[fuhao]=c; } for ( int i= 2 ;i<sumoperate;i++) { int zenjiashu=r.nextInt(max+ 1 )+min; char zenjiac = fuHao(); if (zenjiac== '*' ) { cunshu[shu]=cunshu[shu]*zenjiashu; } else if (zenjiac== '/' ) { cunshu[shu]=cunshu[shu]/zenjiashu; } else { shu++; cunshu[shu]=zenjiashu; fuhao++; cunfuhao[fuhao]=zenjiac; } str=str+zenjiac+zenjiashu; } int zhengquedaan=cunshu[ 0 ]; int cou= 0 ; for ( int j= 0 ;j<=fuhao;j++) { if (cunfuhao[cou]== '+' ) { zhengquedaan+=cunshu[++cou]; } else { zhengquedaan-=cunshu[++cou]; } } if (chachong(str)) { zqda[ccount]=zhengquedaan; System.out.println(arr[ccount]+ "=" ); System.out.println(zhengquedaan); int daan; daan = sc.nextInt(); if (daan!=zhengquedaan) { cuoticount++; cishu[ccount]= 1 ; System.out.println( "回答错误" ); } else System.out.println( "回答正确" ); ccount++; } else { problem(min,max,sumoperate,chengchu); } } public void chuti() { System.out.println( "请输入操作数:" ); sumoperate=sc.nextInt(); System.out.println( "请输入题目个数:" ); sumtitle = sc.nextInt(); System.out.println( "请输入操作数范围:" ); min = sc.nextInt(); max = sc.nextInt(); tishusum=sumtitle; for ( int i= 0 ; i<sumtitle;i++) { problem(); } } } //四年级类 package ceshi; public class si extends san{ public void chuti() { System.out.println( "请输入操作数:" ); sumoperate=sc.nextInt(); System.out.println( "请输入题目个数:" ); sumtitle = sc.nextInt(); System.out.println( "请输入操作数范围:" ); min = sc.nextInt(); max = sc.nextInt(); for ( int i= 0 ; i<sumtitle;i++) { problem(); } } } package ceshi; import java.util.Random; import java.util.Scanner; public class er { static int count= 0 ; static int ccount= 0 ; static int cuoticount= 0 ; static int congzuosum= 1 ; static int tishusum= 0 ; static String []arr = new String[ 100000 ]; static int []zqda = new int [ 100000 ]; static int []cishu = new int [ 100000 ]; static Scanner sc = new Scanner(System.in); int sumtitle; int min; int max; public int getSumtitle() { return sumtitle; } public void setSumtitle( int sumtitle) { this .sumtitle = sumtitle; } public int getMin() { return min; } public void setMin( int min) { this .min = min; } public int getMax() { return max; } public void setMax( int max) { this .max = max; } public char fuHao() { Random random= new Random(); int a; a=random.nextInt( 4 )+ 1 ; if (a== 1 ) return '+' ; if (a== 2 ) return '-' ; if (a== 3 ) return '*' ; if (a== 4 ) return '/' ; return ' ' ; } public void problem() { Random random= new Random(); String s= "" ; int a=random.nextInt(max+ 1 )+min; s+=a; char b=fuHao(); s+=b; int c; if (b== '/' ) { c=random.nextInt(max+ 1 )+min; while (a%c!= 0 ) c=random.nextInt(max+ 1 )+min; s+=c; } else { c=random.nextInt(max+ 1 )+min; s+=c; } int zhengquedaan= 0 ; if (b== '*' ) { zhengquedaan=a*c; } if (b== '/' ) { zhengquedaan=a/c; } if (b== '+' ) { zhengquedaan=a+c; } if (b== '-' ) { zhengquedaan=a-c; } if (chachong(s)) { zqda[ccount]=zhengquedaan; System.out.println(arr[ccount]+ "=" ); int daan; daan = sc.nextInt(); if (daan!=zhengquedaan) { cuoticount++; cishu[ccount]= 1 ; System.out.println( "回答错误" ); } else System.out.println( "回答正确" ); ccount++; } else { problem(); } } public boolean chachong(String str) { if (count== 0 ) { arr[ 0 ]=str; count++; return true ; } else { for ( int i= 0 ;i<count;i++) if (str.equals(arr[i])) return false ; arr[count]=str; count++; } return true ; } public static int shifouchongzuo() { System.out.println( "是否需要错题重做:(1.是 2.否)" ); int chongzuoma; chongzuoma = sc.nextInt(); return chongzuoma; } public void chongzuo() { System.out.println( "错误率:" +cuoticount* 100 /tishusum+ "%" ); while ( true ) { if (shifouchongzuo()== 1 ) { int n=cuoticount; cuoticount= 0 ; lop: for ( int i= 0 ;i<n;i++) { for ( int j= 0 ;i<tishusum;j++) { if (cishu[j]==congzuosum) { System.out.println(arr[j]+ "=" ); int da; da = sc.nextInt(); if (da!=zqda[j]) { System.out.println( "正确答案:" +zqda[j]); cishu[j]+= 1 ; cuoticount++; break lop; } } } } congzuosum++; System.out.println( "错误率:" +cuoticount* 100 /n+ "%" ); } else { jielun(); break ; } } } public void jielun() { for ( int j= 0 ;j<tishusum;j++) { if (cishu[j]!= 0 ) { System.out.println(arr[j]+ "=" +zqda[j]+ " 你错了" +cishu[j]+ "次" ); } } } public void chuti() { System.out.println( "请输入题目个数:" ); sumtitle = sc.nextInt(); System.out.println( "请输入操作数范围:" ); min = sc.nextInt(); max = sc.nextInt(); tishusum=sumtitle; for ( int i= 0 ; i<sumtitle;i++) { problem(); } } } |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· winform 绘制太阳,地球,月球 运作规律
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人