小学数学Java

package xxs;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class xxs {
static int SCORE = 0; static int OLDSCORE = 0;
static Scanner input=new Scanner(System.in);
static String ID = “”; static String OLDID = “”;
static long BETWEEN = 0; static long OLDBETWEEN = 0;
boolean user = true;

public static void start() {

	System.out.println("请输入用户ID号:");
	String useid = input.next();
	ID = useid;
	if(xxs.use(useid) ) {
		xxs.next();
	}else {
		System.out.println("ID不合理请重新输入!");
		xxs.start();
	}
}

public static void main(String[] args) {
	xxs s = new xxs();
	s.start();
	

}

//判断是否符合ID规则
public static boolean use(String id) {
int k=0;
for (int i=0; i<2; i++) {
if (Character.isUpperCase(id.charAt(i))) {
k++;
}else k–;

	}
	for(int i=2; i<id.length(); i++) {
		if (Character.isDigit(id.charAt(i))) {
			k++;
		}else k--;	
	}
	if(k==6) {
		return true;
	}else return false;
}

public static void next() {
	
	System.out.println("(1)开始测试");
	System.out.println("(2)检查分数");
	System.out.println("(3)退出");
	System.out.println("输入1,2,3选择选项");
	switch(input.nextInt()) {
		case 1 :	xxs.test();break;
		case 2 :	xxs.check();break;
		case 3 :	xxs.exit();break;
	}
}

//测验
public static void test() {
String[][] q = new String[11][3];
q[0][0] =“问题”+" “+”|";
q[0][1] = “正确答案”+"|";
q[0][2] = “你的答案”;
int oldwei = 4;
//计算
long from = System.currentTimeMillis();
int k = 1;
for (int i = 0; i < 10; ++i) {
int value = 0;
int wei = (int) (Math.random() * 4); // 运算符
int a = (int) (Math.random() * 99) + 1; // 数a
int b = (int) (Math.random() * 99) + 1; // 数b
int sum = 0;
if(oldweiwei) {
if(wei
0) { wei = oldwei+1; }
else if(wei3) {wei = oldwei-2;}
else wei =oldwei+1;
}
switch (wei) {
case 0: sum = a + b; break;
case 1: sum = a - b; break;
case 2: sum = a * b; break;
case 3: sum = a / b; break; }
if(wei
0) {
oldwei = wei;
if(sum<=100 && sum>=0) {
System.out.print(a+"+"+b+"=");
q[k][1] = a+b+" “;
q[k][0] = a+”+"+b+"=";
value = input.nextInt();
q[k][2] = value+" “;
if(valuesum) {
SCORE +=10;
}
k++;
} else --i;
} else if (wei
1 ){
oldwei = wei;
if(sum<=100 && sum>=0) {
System.out.println(a+”-"+b+"=");
q[k][1] = a-b+"";
q[k][0] = a+"-"+b+"=";
value = input.nextInt();
q[k][2] = value+" “;
if(valuesum) {
SCORE +=10;
}
k++;
}else --i;
} else if(wei
2 ){
oldwei = wei;
if(sum<=100 && sum>=0) {
System.out.println(a+”"+b+"=");
q[k][1] = a
b+"";
q[k][0] = a+"*"+b+"=";
value = input.nextInt();
q[k][2] = value+" “;
if(valuesum) {
SCORE +=10;
}
k++;
}else --i;
} else if(wei
3){
oldwei = wei;
if(sum<=100 && sum>=0) {
System.out.println(a+”/"+b+"=");
q[k][1] = a/b+"";
q[k][0] = a+"/"+b+"=";
value = input.nextInt();
q[k][2] = value+" ";
if(value==sum) {
SCORE +=10;
}
k++;
}else --i;
}
}
long to = System.currentTimeMillis();
BETWEEN = (to-from)/1000;
try {
xxs.fileos(ID, SCORE, BETWEEN);
} catch (IOException e) {
e.printStackTrace();
}

	OLDSCORE = SCORE;
	OLDID = ID;
	OLDBETWEEN = BETWEEN;
	SCORE = 0; 				//重置
	ID = "";
	BETWEEN = 0;

//问题|正确答案|你的答案
System.out.print(“问题”+" “+”|"+" “);
System.out.print(“正确答案”+” “+”|"+" “);
System.out.print(“你的答案”);
for(int i = 1;i<11;i++) {
System.out.println();
for(int j = 0;j<3;j++) {
if(j0) {
System.out.print(q[i][j] +"\t");
}else if(j
2){
System.out.print(” “+q[i][j] +”\t");
}else System.out.print(" “+q[i][j] +”\t");

		}
	}
	System.out.println();

//check或者exit
System.out.println(“你可以输入check检查你的成绩。”);
System.out.println(“你可以输入exit退出程序。”);
String a = input.next();
if(a.equals(“check”)) xxs.check();
else if(a.equals(“exit”)) xxs.exit();
else xxs.start(); //第二位同学使用
}
//检查
public static void check() {
System.out.println(“your–”+OLDID);
System.out.println(“your–”+OLDSCORE+“分”);
System.out.println(“your–”+OLDBETWEEN+“秒”);
xxs.exit();
}
//退出
public static void exit() {
System.out.println(“程序已退出!”);
System.exit(0) ;
}
//保存成绩到 D:/record.txt
public static void fileos(String id, long score,long between) throws IOException {
File myfile = new File(“D:/record.txt”);
if(!myfile.exists()) {
try {
myfile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}

	FileWriter fw = new FileWriter("D:/record.txt",true);
	String line = System.getProperty("line.separator");
	String result = "你的ID:"+id+"--"+"你的成绩"+score+"--"+"你所用时间:"+between+"秒";
	fw.write("你以前的记录是:"+"\r");
	fw.write(result);
	fw.write(line);
	fw.close();

// System.out.println(myfile.exists());
// FileReader fr = new FileReader(“D:/record.txt”);
// int temp = 0;
// while((temp = fr.read())!=-1 )
// System.out.print((char)(temp)+" ");
// fr.close();

}

}

©️2020 CSDN 皮肤主题: 1024 设计师:上身试试 返回首页