首页 > 其他分享 >四则运算4

四则运算4

时间:2022-10-16 17:35:13浏览次数:44  
标签:min int max 四则运算 System print out

package 加减法;
import java.util.ArrayList;
import java.util.Random;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
lv2 a=new lv2();
lv3 b=new lv3();
lv4 c=new lv4();
lvmenu();
int choose=sc.nextInt();
int max,min;
max=100;
min=0;
while(choose!=0) {
switch(choose){
case 1:{
max=setmax();
min=setmin();
if(min>max) {
int k;
k=min;
min=max;
max=k;
}
System.out.println(max+" "+min);
break;
}
case 2:{
a.setmax(max);
a.setmin(min);
a.going(max, min);
break;
}
case 3:{
b.setmax(max);
b.setmin(min);
b.going(max, min);
break;
}
case 4:{
c.setmax(max);
c.setmin(min);
c.going(max, min);
break;
}
case 5:{
a.mis();
b.mis();
c.mis();
}
}
lvmenu();
choose=sc.nextInt();
}
}
public static void lvmenu() {
System.out.println("欢迎使用四则运算系统");
System.out.println("1.参数设置");
System.out.println("2.小学二年级口算题");
System.out.println("3.小学三年级口算题");
System.out.println("4.小学四年级口算题");
System.out.println("5.错题本");
}
public static int setmax() {
System.out.print("请输入最大值");
Scanner sc=new Scanner(System.in);
int max=sc.nextInt();
return max;
}
public static int setmin() {
System.out.print("请输入最小值");
Scanner sc=new Scanner(System.in);
int min=sc.nextInt();
return min;
}
public static void easy() {
int bingo=0,sum=0;
int x[]=new int[100];
int y[]=new int[100];
int z[]=new int[100];
System.out.println("请输入需要生成多少道数学题");
int n;
Scanner sc=new Scanner(System.in);
Random r=new Random();
n=sc.nextInt();
int test=sc.nextInt();
int test1=2;
int max,min;
System.out.println("请输入最大值");
max=sc.nextInt();
System.out.println("请输入最小值");
min=sc.nextInt();
int joker=max-min;
Test tes=new Test();
for(int i=1;i<=n;i++) {
int a=(int)(Math.random()*joker+min);
int b=(int)(Math.random()*joker+min);
int c=(int)(Math.random()*4+1);

int d=1;
//d=(int)(Math.random()*10+1);
if(d<=5) {
if(a<b) {
int k;
k=b;
b=a;
a=k;
}
putout(a,b,c,i);
if(d>5&&test1==1)
{
int t=(int)(Math.random()*joker+min);
int e=(int)(Math.random()*4+1);

if(d<=8) {
putout(a,b,c,i);
sign(e);
System.out.print(t);
}
else if(d==9){
System.out.print("(");
putout(a,b,c,i);
System.out.print(")");
sign(e);
System.out.print(t);
}
else if(d==10) {
System.out.print("第"+i+"题 "+a);
sign(c);
System.out.print("("+b);

sign(e);
System.out.print(t+")");
}
}
System.out.print("=");
int score=sc.nextInt();
int end=end(a,b,c);
if(score==end) {
bingo++;
}
else {
System.out.println("真可惜,答错了");
x[sum]=a;
y[sum]=b;
z[sum++]=c;
}
//System.out.print("\t");
//if(i%len==0)
//System.out.print("\n");
}
}
System.out.println("\n正确率:"+bingo*100/n+"%");
System.out.println("错题数:"+sum);
for(int i=0;i<sum;i++) {
System.out.print("第"+(i+1)+"题 "+x[i]);
sign(z[i]);
System.out.println(y[i]+"="+end(x[i],y[i],z[i]));
}
}
public static void sign(int c) {
if(c==1)
System.out.print("+");
else if(c==2)
System.out.print("-");
else if(c==3)
System.out.print("*");
else
System.out.print("➗");
}
public static int end(int a,int b,int c) {
int endd=0;
if(c==1){
endd=a+b;
}
if(c==2) {
endd=a-b;
}
if(c==3) {
endd=a*b;
}
if(c==4) {
endd=a/b;
}
return endd;
}
public static void putout(int a,int b,int c,int i) {
System.out.print("第"+i+"题 "+a);
sign(c);
System.out.print(b);
}
}

package 加减法;

import java.util.Scanner;

public class lv4 extends lv2 {
Scanner sc=new Scanner(System.in);
int max,min,joker;
int a,b,c,d,e,f,g,h,m,n;
int mistake=0;
int mistakea[]=new int[1000];
int mistakeb[]=new int[1000];
int mistakec[]=new int[1000];
int mistaked[]=new int[1000];
int mistakee[]=new int[1000];
int mistakef[]=new int[1000];
int mistakeg[]=new int[1000];
int mistakeh[]=new int[1000];
int mistakem[]=new int[1000];
public void setmax(int max) {
if(max>1000)
max=1000;
this.max=max;
}
public void setmin(int min) {
if(min<1)
min=1000;
this.min=min;
}
public void setn() {
System.out.print("请输入生成题目的数量");
this.n=sc.nextInt();
}
public void setting() {
joker=max-min;
this.a=(int)(Math.random()*joker+min);
this.b=(int)(Math.random()*joker+min);
this.c=(int)(Math.random()*4+1);
this.d=(int)(Math.random()*joker+min);
this.e=(int)(Math.random()*joker+min);
this.f=(int)(Math.random()*4+1);
this.g=(int)(Math.random()*4+1);
this.h=(int)(Math.random()*joker+min);
this.m=(int)(Math.random()*4+1);
}
public void going(int max,int min) {
setmax(max);
setmin(min);
setn();
System.out.println(n);
for(int i=0;i<n;i++) {
setting();
System.out.print("((("+a);
sign(c);
System.out.print(b+")");
sign(f);
System.out.print(d+")");
sign(g);
System.out.print(e+")");
sign(m);
System.out.print(h+"=");
int result=sc.nextInt();
if(result==com(a,b,c,d,e,f,g,h,m)) {
System.out.println("答对了!");
}

else {System.out.print(com(a,b,c,d,e,f,g,h,m));
mistakea[mistake]=a;
mistakeb[mistake]=b;
mistakec[mistake]=c;
mistaked[mistake]=d;
mistakee[mistake]=e;
mistakef[mistake]=f;
mistakeh[mistake]=h;
mistakem[mistake]=m;
mistakeg[mistake++]=g;
System.out.println("很遗憾,答错了!");
}
}
System.out.println("\n正确率:"+(n-mistake)*100/n+"%");
System.out.println("错题数:"+mistake);
mis();
}
public void mis() {
Scanner sc=new Scanner(System.in);
for(int i=0;i<mistake;i++) {
System.out.print('第'+i+"题((("+mistakea[i]);
sign(mistakec[i]);
System.out.print(mistakeb[i]+")");
sign(mistakef[i]);
System.out.print(mistaked[i]+")");
sign(mistakeg[i]);
System.out.println(mistakee[i]+")");
sign(mistakem[i]);
System.out.println(mistakeh[i]+"=");
int result=sc.nextInt();
if(result==com(a,b,c,d,e,f,g,h,m)) {
System.out.println("答对了!");
}
else {System.out.print(com(mistakea[i],mistakeb[i],mistakec[i],mistaked[i],mistakee[i],mistakef[i],mistakeg[i],mistakeh[i],mistakem[i]));
mistakea[mistake]=a;
mistakeb[mistake]=b;
mistakec[mistake]=c;
mistaked[mistake]=d;
mistakee[mistake]=e;
mistakef[mistake]=f;
mistakeg[mistake++]=g;
System.out.println("很遗憾,答错了!");
}
}
}
public int com(int a,int b,int c,int d,int e,int f,int g,int h,int m) {
int endd=0;
if(c==1){
endd=a+b;
}
if(c==2) {
endd=a-b;
}
if(c==3) {
endd=a*b;
}
if(c==4) {
endd=a/b;
}
if(f==1){
endd+=b;
}
if(f==2) {
endd-=d;
}
if(f==3) {
endd*=d;
}
if(f==4) {
endd/=d;
}
if(g==1){
endd+=e;
}
if(g==2) {
endd-=e;
}
if(g==3) {
endd*=e;
}
if(g==4) {
endd/=e;
}
if(m==1){
endd+=h;
}
if(m==2) {
endd-=h;
}
if(m==3) {
endd*=h;
}
if(m==4) {
endd/=h;
}
return endd;
}
}

 

package 加减法;

import java.util.Scanner;

public class lv3 extends lv2{
Scanner sc=new Scanner(System.in);
int max,min,joker;
int a,b,c,d,e,f,g,n;
int mistake=0;
int mistakea[]=new int[1000];
int mistakeb[]=new int[1000];
int mistakec[]=new int[1000];
int mistaked[]=new int[1000];
int mistakee[]=new int[1000];
int mistakef[]=new int[1000];
int mistakeg[]=new int[1000];
public void setmax(int max) {
if(max>1000)
max=1000;
this.max=max;
}
public void setn() {
System.out.print("请输入生成题目的数量");
this.n=sc.nextInt();
}
public void setting() {
joker=max-min;
this.a=(int)(Math.random()*joker+min);
this.b=(int)(Math.random()*joker+min);
this.c=(int)(Math.random()*4+1);
this.d=(int)(Math.random()*joker+min);
this.e=(int)(Math.random()*joker+min);
this.f=(int)(Math.random()*4+1);
this.g=(int)(Math.random()*4+1);
}
public void going(int max,int min) {
setmax(max);
setmin(min);
setn();
System.out.println(n);
for(int i=0;i<n;i++) {
setting();
System.out.print("(("+a);
sign(c);
System.out.print(b+")");
sign(f);
System.out.print(d+")");
sign(g);
System.out.print(e+"=");
int result=sc.nextInt();
if(result==com(a,b,c,d,e,f,g)) {
System.out.println("答对了!");
}

else {System.out.print(com(a,b,c,d,e,f,g));
mistakea[mistake]=a;
mistakeb[mistake]=b;
mistakec[mistake]=c;
mistaked[mistake]=d;
mistakee[mistake]=e;
mistakef[mistake]=f;
mistakeg[mistake++]=g;
System.out.println("很遗憾,答错了!");
}
}
System.out.println("\n正确率:"+(n-mistake)*100/n+"%");
System.out.println("错题数:"+mistake);
mis();
}
public void mis() {
Scanner sc=new Scanner(System.in);
for(int i=0;i<mistake;i++) {
System.out.print("第"+i+"题(("+mistakea[i]);
sign(mistakec[i]);
System.out.print(mistakeb[i]+")");
sign(mistakef[i]);
System.out.print(mistaked[i]+")");
sign(mistakeg[i]);
System.out.println(mistakee[i]+"=");
int result=sc.nextInt();
if(result==com(a,b,c,d,e,f,g)) {
System.out.println("答对了!");
}
else {System.out.print(com(mistakea[i],mistakeb[i],mistakec[i],mistaked[i],mistakee[i],mistakef[i],mistakeg[i]));
mistakea[mistake]=a;
mistakeb[mistake]=b;
mistakec[mistake]=c;
mistaked[mistake]=d;
mistakee[mistake]=e;
mistakef[mistake]=f;
mistakeg[mistake]=g;
System.out.println("很遗憾,答错了!");
}
}

}
public int com(int a,int b,int c,int d,int e,int f,int g) {
int endd=0;
if(c==1){
endd=a+b;
}
if(c==2) {
endd=a-b;
}
if(c==3) {
endd=a*b;
}
if(c==4) {
endd=a/b;
}
if(f==1){
endd+=b;
}
if(f==2) {
endd-=d;
}
if(f==3) {
endd*=d;
}
if(f==4) {
endd/=d;
}
if(g==1){
endd+=e;
}
if(g==2) {
endd-=e;
}
if(g==3) {
endd*=e;
}
if(g==4) {
endd/=e;
}
return endd;
}
}

package 加减法;

import java.util.Scanner;

public class lv2 {
Scanner sc=new Scanner(System.in);
int max,min,joker;
int a,b,c,n;
int mistake=0;
int mistakea[]=new int[1000];
int mistakeb[]=new int[1000];
int mistakec[]=new int[1000];
public void setmax(int max) {
if(max>100)
max=100;
this.max=max;
}
public void setmin(int min) {
if(min<1)
min=1;
this.min=min;
}
public void setn() {
System.out.print("请输入生成题目的数量");
this.n=sc.nextInt();
}
public void setting() {
joker=max-min;
this.a=(int)(Math.random()*joker+min);
this.b=(int)(Math.random()*joker+min);
this.c=(int)(Math.random()*4+1);
}
public void going(int max,int min) {
setmax(max);
setmin(min);
setn();
for(int i=0;i<n;i++) {
setting();
System.out.print(a);
sign(c);
System.out.print(b+"=");
int result=sc.nextInt();
if(result==com(a,b,c)) {
System.out.println("答对了!");
}
else {
mistakea[mistake]=a;
mistakeb[mistake]=b;
mistakec[mistake++]=c;
System.out.println("很遗憾,答错了!");
}
}
System.out.println("\n正确率:"+(n-mistake)*100/n+"%");
System.out.println("错题数:"+mistake);
mis();
}
public void mis() {
for(int i=0;i<mistake;i++) {
System.out.print("第"+i+"题"+mistakea[i]);
sign(mistakec[i]);
System.out.print(mistakeb[i]+"=");
int result=sc.nextInt();
if(result==com(a,b,c)) {
System.out.println("答对了!");
}
else {
System.out.println("很遗憾,答错了!");
}
System.out.println("\n正确率:"+(n-mistake)*100/n+"%");
System.out.println("错题数:"+mistake);
}
}
public void sign(int c) {
if(c==1)
System.out.print("+");
else if(c==2)
System.out.print("-");
else if(c==3)
System.out.print("*");
else
System.out.print("➗");
}
public int com(int a,int b,int c) {
int endd=0;
if(c==1){
endd=a+b;
}
if(c==2) {
endd=a-b;
}
if(c==3) {
endd=a*b;
}
if(c==4) {
endd=a/b;
}
return endd;
}
}

标签:min,int,max,四则运算,System,print,out
From: https://www.cnblogs.com/ruipengli/p/16796617.html

相关文章

  • 栈的链式储存结构及应用:四则运算表达式求值(中缀表达式转化为后缀表达式并求值)
    遇到的问题一:SegmentationFault(存储器区块错误)遇到的问题二:函数内变量一经声明其地址已固定,导致同一结点反复入栈遇到的问题三:对字符串如何标记和提取单个数值/*//////......
  • 四则运算
    //这个代码吧略有缺陷四则运算的乘除与加减只能从左到右依次计算还没想好怎么做importjava.util.Random;importjava.util.Scanner;publicclasstest{publicst......
  • 另一个四则运算
    importcom.sun.javaws.IconUtil;//这个跟那个差不多进步在于类至于三年级没写道理相同importjava.util.Scanner;publicclassMain{publicstaticvoidmain(St......
  • 动手动脑01四则运算计算器
    完成一个计算器阶段1:1、定义主界面菜单,1、参数设置2、小学二年级口算题3、小学三年级口算题4、小学四年级口算题5、错题集其中参数设置包括出题个数(缺省值为30)、操作......
  • 四则运算课堂测试(三)
    阶段1:1、定义主界面菜单,1、参数设置2、小学二年级口算题3、小学三年级口算题4、小学四年级口算题5、错题集其中参数设置包括出题个数(缺省值为30)、操作数数值范围。......
  • 9.30四则运算课堂测试三
    阶段1:1、定义主界面菜单,1、参数设置2、小学二年级口算题3、小学三年级口算题4、小学四年级口算题5、错题集其中参数设置包括出题个数(缺省值为30)、操作数数值范围。......
  • Java 四则运算 继承版
    packageT1;importjava.util.Scanner;publicclassA_Text{staticinttitle_n=30;staticScannercin=newScanner(System.in);publicstaticvoidmain(......
  • 四则运算——初级
    SEIndividualProject目录SEIndividualProject四则运算——初级题目需求分析设计编码重构代码测试思路说明时间花费比较已知问题四则运算——初级题目编写一个四则......
  • 四则运算测试二
    packageoperation;importjava.util.Random;importjava.util.Scanner;publicclassoperation{publicstaticintnumber=0;//个数publicstaticintmult=......
  • 关于从“’四则运算程序‘例子出发, 逐步构建一个能解决实际问题的’软件‘”的思考
    1.首先根据作业要求写出一个简单的程序    它可以达到的效果为:首先运行程序,输入一个数字,该数字为想要生成的题目的数量,输入数字后能生成对应数目的题目和答案。题......