00
import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class Demo { public static void main(String[] args) { Scanner in = new Scanner(System.in); Counter counter=new Counter(); PrintWriter out = null; try { out = new PrintWriter("text.txt"); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } int sum = 0; for (int i = 1; i <=10; i++) { int a = (int) Math.round(Math.random() * 100); int b = (int) Math.round(Math.random() * 100); int m= (int) Math.round(Math.random() * 3); switch(m) { case 0: System.out.println(i+": "+a+"/"+b+"="); while(b==0){ b = (int) Math.round(Math.random() * 100); } int c0 = in.nextInt(); out.println(a+"/"+b+"="+c0); if (c0 == counter.division(a, b)) { sum += 10; System.out.println("恭喜答案正确"); } else { System.out.println("抱歉,答案错误"); } break; case 1: System.out.println(i+": "+a+"*"+b+"="); int c = in.nextInt(); out.println(a+"*"+b+"="+c); if (c == counter.multiplication(a, b)) { sum += 10; System.out.println("恭喜答案正确"); } else { System.out.println("抱歉,答案错误"); } break; case 2: System.out.println(i+": "+a+"+"+b+"="); int c1 = in.nextInt(); out.println(a+"+"+b+"="+c1); if (c1 == counter.add(a, b)) { sum += 10; System.out.println("恭喜答案正确"); } else { System.out.println("抱歉,答案错误"); } break ; case 3: System.out.println(i+": "+a+"-"+b+"="); int c2 = in.nextInt(); out.println(a+"-"+b+"="+c2); if (c2 == counter.reduce(a, b)) { sum += 10; System.out.println("恭喜答案正确"); } else { System.out.println("抱歉,答案错误"); } break ; } } System.out.println("成绩"+sum); out.println("成绩:"+sum); out.close(); } }
main
public class Counter { private int a; private int b; public int add(int a,int b) { return a+b; } public int reduce(int a,int b) { return a-b; } public int multiplication(int a,int b) { return a*b; } public int division(int a,int b) { if(b!=0) return a/b; else return 0; } }
Counter
原文地址:https://www.cnblogs.com/2017xinghui/p/9851358.html
时间: 2024-10-08 01:30:23