没错!还是那神奇的四则运算,它,,又来啦!!!
话不多说,直接上代码!!!
本次实践,主要实现了分年级的继承功能问题、错题集整理和重做问题、查看正确率问题、还有之前已经实现过的四则运算问题,相当于“四则运算中的战斗机”了吧,好有成就感啊喂!
//Main.java
import java.util.Scanner;
public class Main{
static int sum;
static int count;
er ee=new er();
san ss=new san();
si ii=new si();
public static void main(String[] args) {
menu1();
}
//主菜单
public static void menu1(){
while(true) {
Scanner sc = new Scanner(System.in);
System.out.println("******************");
System.out.println("1、参数设置:");
System.out.println("2、小学二年级口算题");
System.out.println("3、小学三年级口算题");
System.out.println("4、小学四年级口算题");
System.out.println("5、错题集");
System.out.println("******************");
int c = sc.nextInt();
if (c == 1) {
can();
}
if(c==2){
er.getAnswer1(sum,count);
}
if(c==3){
san.getAnswer1(sum,count);
}
if(c==4){
si.getAnswer1(sum,count);
}
if(c==5){//错题集
System.out.println("请选择:1、二年级 2、三年级 3、四年级");
int x=sc.nextInt();
if(x==1){
er.cuoTiJi(sum);
}
if(x==2){
san.cuoTiJi(sum);
}
if(x==3){
si.cuoTiJi(sum);
}
System.out.println("请根据以上题目进行修正和重练");
}
}
}
//错题集
//参数设置
public static void can(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入你想要打印的题目数量:");
sum = sc.nextInt();//iControl用于控制生成题目总数
System.out.println("请输入操作数的个数:");
count = sc.nextInt();
}
}
//er.java
import java.util.Random;
import java.util.Scanner;
public class er{
static int err;
static String[] timu=new String[1001];
static String[] error=new String[1001];
static String[] aa=new String[1001];
static String[] daanCom=new String[1001];
static String[] daanPerson=new String[1001];
static int[]cuowu1=new int[1001];
static int[]cuowu2=new int[1001];
public static void getAnswer1(int sum,int count){
Scanner sc = new Scanner(System.in);
Random r = new Random();
err = 0;
int x, y ;
for (int i = 0; i < sum; i++) {
String str = "";//记录题目
x = r.nextInt(1000);
str += String.valueOf(x);
for (int j = 0; j < count - 1; j++) {
y = r.nextInt(1000);
int fuhao = r.nextInt(1, 4);
switch(fuhao) {
case 1:
str += " + ";
x+=y;
break;
case 2:
str += " - ";
x-=y;
break;
case 3:
str += " * ";
x=x*y;
break;
case 4:
str += " / ";
x=x/y;
break;
}
str+=String.valueOf(y);
}
str+=" = ";
timu[i]=str;
daanCom[i]=String.valueOf(x);
System.out.print(str);
daanPerson[i]=sc.nextLine();
if(!(daanCom[i].equals(daanPerson[i]))) {
cuowu1[err]=i;//cun下标
cuowu2[cuowu1[err]]++;//存错误次数
err++;
}
}
}
//错题集
public static void cuoTiJi(int sum) {
System.out.println("正确率:"+(double)(sum-err)/sum*100.0+"%");
Scanner sc=new Scanner(System.in);
for (int i = 0; i < err; i++) {
System.out.println(timu[cuowu1[i]]);
}
System.out.println("请选择是否重做:1、是 2、否");
int m=sc.nextInt();
if(m==1) {
chongZuo();
}
}
public static void chongZuo(){
Scanner sc=new Scanner(System.in);
for (int i = 0; i < err; i++) {
System.out.println(timu[cuowu1[i]]);
aa[i]=sc.nextLine();
if(!(aa[i].equals(daanCom[i]))) {
System.out.println("答错啦!");
}
}
}
}
//san.java
import java.util.Random;
import java.util.Scanner;
public class san extends er{
static int err;
static String[] timu=new String[1001];
static String[] error=new String[1001];
static String[] daanCom=new String[1001];
static String[] daanPerson=new String[1001];
static int[]cuowu1=new int[1001];
static int[]cuowu2=new int[1001];
public static void getAnswer1(int sum,int count){
Scanner sc = new Scanner(System.in);
Random r = new Random();
err = 0;
int x, y ;
for (int i = 0; i < sum; i++) {
String str = "";//记录题目
x = r.nextInt(1000);
str += String.valueOf(x);
for (int j = 0; j < count - 1; j++) {
y = r.nextInt(1000);
int fuhao = r.nextInt(1, 4);
switch(fuhao) {
case 1:
str += " + ";
x+=y;
break;
case 2:
str += " - ";
x-=y;
break;
case 3:
str += " * ";
x=x*y;
break;
case 4:
str += " / ";
x=x/y;
break;
}
str+=String.valueOf(y);
}
str+=" = ";
timu[i]=str;
daanCom[i]=String.valueOf(x);
System.out.print(str);
daanPerson[i]=sc.nextLine();
if(!(daanCom[i].equals(daanPerson[i]))) {
cuowu1[err]=i;//cun下标
cuowu2[cuowu1[err]]++;//存错误次数
err++;
}
}
}
//错题集
public static void cuoTiJi(int sum) {
System.out.println("正确率:"+(double)(sum-err)/sum*100.0+"%");
Scanner sc=new Scanner(System.in);
for (int i = 0; i < err; i++) {
System.out.println(timu[cuowu1[i]]);
}
System.out.println("请选择是否重做:1、是 2、否");
int m=sc.nextInt();
if(m==1) {
chongZuo();
}
}
public static void chongZuo(){
Scanner sc=new Scanner(System.in);
for (int i = 0; i < err; i++) {
System.out.println(timu[cuowu1[i]]);
aa[i]=sc.nextLine();
if(!(aa[i].equals(daanCom[i]))) {
System.out.println("答错啦!");
}
}
}
}
//si.java
import java.util.Random;
import java.util.Scanner;
public class si extends san {
static int err;
static String[] timu = new String[1001];
static String[] error = new String[1001];
static String[] daanCom = new String[1001];
static String[] daanPerson = new String[1001];
static int[] cuowu1 = new int[1001];
static int[] cuowu2 = new int[1001];
static int x;
static int y;
static int m1,m2,c1,c2,cc;
public static void getAnswer1(int sum, int count) {
Scanner sc = new Scanner(System.in);
Random random = new Random();
for (int j = 0; j < sum; j++) {
String str = "";//存储题目
boolean ss = true;
int left = random.nextInt(count - 1);
int right = random.nextInt(count - left) + left + 1;
/*for (int i = 0; i < count * 2 - 1; i++) {
getDo[i] = random.nextInt(1000);
}
for (int t = 0; t < count; t++) {
admin[j] += getDo[t * 2] * t;
}
for (int k = 0; k < j; k++) {
if (admin[k] == admin[j]) {
ss = false;
break;
}
}*/
if(ss){
for(int m=0;m<count-1;m++){//符号的个数
m1=random.nextInt(1,2);
if(m1==1){
str+="(";
c1++;
}
x=random.nextInt(1000);
str+=x;
y=random.nextInt(1000);
cc=random.nextInt(1,4);
if(cc==1){
str+="+";
x+=y;
}
if(cc==2){
str+="-";
x-=y;
}
if(cc==3){
str+="*";
x=x*y;
}
if(cc==4){
str+="/";
x=x/y;
}
str+=y;
if(c1!=0&&c1!=c2){
str+=")";
c2++;
}
cc=random.nextInt(1,4);
if(cc==1&&m!=count-2){
str+="+";
x+=y;
m++;
}
if(cc==2&&m!=count-2){
str+="-";
x-=y;
m++;
}
if(cc==3&&m!=count-2){
str+="*";
x=x*y;
m++;
}
if(cc==4&&m!=count-2){
str+="/";
x=x/y;
m++;
}
}
//存储题目--计算结果
str += "=";
timu[j] = str;
daanCom[j] = String.valueOf(x);
System.out.print(str);
daanPerson[j] = sc.nextLine();
if (!(daanCom[j].equals(daanPerson[j]))) {
cuowu1[err] = j;//cun下标
cuowu2[cuowu1[err]]++;//存错误次数
err++;
}
}
/*if (ss) {
for (int t = 0; t < count * 2 - 1; t++) {
x=random.nextInt(1000);
y=random.nextInt(1000);
if (2 * left == t) {
str += "(";
str += String.valueOf(x);
}
if (t % 2 == 0 && t != count * 2 - 2) {
str += String.valueOf(y);
if (x % 4 == 1) {
str += "+";
x=x+y;
} else if (x % 4 == 2) {
str += "-";
x=x-y;
} else if (x % 4 == 3) {
str += "*";
x=x*y;
} else if (x % 4 == 0) {
str += "/";
x=x/y;
}
}
if (2 * right - 2 == t) {
str += ")";
}else if (t == count * 2 - 2) {
str += String.valueOf(x);
if (x % 4 == 1) {
str += "+";
x=x+y;
} else if (x % 4 == 2) {
str += "-";
x=x-y;
} else if (x % 4 == 3) {
str += "*";
x=x*y;
} else if (x % 4 == 0) {
//System.out.print("/ ");
str += "/";
x=x/y;
}
if (2 * right - 2 == t) {
str += ")";
}
}
}
//存储题目--计算结果
str += "=";
timu[j] = str;
daanCom[j] = String.valueOf(x);
System.out.print(str);
daanPerson[j] = sc.nextLine();
if (!(daanCom[j].equals(daanPerson[j]))) {
cuowu1[err] = j;//cun下标
cuowu2[cuowu1[err]]++;//存错误次数
err++;
}
}*/
}
}
//错题集
public static void cuoTiJi(int sum) {
System.out.println("正确率:"+(double)(sum-err)/sum*100.0+"%");
Scanner sc=new Scanner(System.in);
for (int i = 0; i < err; i++) {
System.out.println(timu[cuowu1[i]]);
}
System.out.println("请选择是否重做:1、是 2、否");
int m=sc.nextInt();
if(m==1) {
chongZuo();
}
}
public static void chongZuo(){
Scanner sc=new Scanner(System.in);
for (int i = 0; i < err; i++) {
System.out.println(timu[cuowu1[i]]);
aa[i]=sc.nextLine();
if(!(aa[i].equals(daanCom[i]))) {
System.out.println("答错啦!");
}
}
}
}