考试系统
Posted 陌尘枫
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了考试系统相关的知识,希望对你有一定的参考价值。
设计实现一个小学生数学考试系统,完成随机出题(简单的四则运算),学生答题,自动判分的功能。
1 package experiment; 2 3 import java.util.Scanner; 4 5 6 public class Arithmetic { 7 public static void main(String args[]) { 8 begin_test(); 9 } 10 //随机产生数字 11 public static double r_random(int min, int max) { 12 double ii; 13 ii = (double)(min + Math.random() * (max - min + 1)); 14 return ii; 15 } 16 //随机产生符号 17 public static char make_sym() 18 { 19 int ii; 20 ii = (int)(Math.random() * 3); 21 if(ii == 0) 22 return ‘+‘; 23 else if(ii == 1) 24 return ‘-‘; 25 else if(ii == 2) 26 return ‘*‘; 27 else 28 return ‘/‘; 29 } 30 //随机产生式子 31 public static int make_formula(int min, int max) 32 { 33 int ii, ij; 34 char operator; 35 36 37 ii = (int)r_random(min, max); 38 ij = (int)r_random(min, max); 39 40 operator = make_sym(); 41 System.out.println("随机产生的四则运算为:" + ii + " " + operator + " " + ij + " = ?"); 42 if(operator == ‘+‘) 43 return (ii + ij); 44 else if(operator == ‘-‘) 45 return (ii - ij); 46 else if(operator == ‘*‘) 47 return (ii * ij); 48 else 49 { 50 return Math.round(ii / ij); 51 } 52 } 53 54 //判断结果是否正确 55 public static boolean test( int min, int max) 56 { 57 double answer, r_answer; 58 System.out.println("请输入答案(注意除法时答案四舍五入取整):"); 59 Scanner sc = new Scanner(System.in); 60 answer = make_formula(min, max); 61 r_answer = sc.nextDouble(); 62 if(answer == r_answer) { 63 System.out.println("正确!"); 64 return true; 65 } 66 else { 67 System.out.println("错误!"); 68 return false; 69 } 70 } 71 72 //计分 73 public static double score(int num, int min, int max) { 74 double sum = 0; 75 double one_score = (float)(100 / num); 76 for(int i = 0; i < num; i++) { 77 if(test(min, max)) { 78 sum += one_score; 79 } 80 else { 81 continue; 82 } 83 } 84 return sum; 85 } 86 //考试开始 87 public static void begin_test() { 88 int num, min, max; 89 double sum; 90 Scanner sc = new Scanner(System.in); 91 System.out.println("请输入需要产生的试题数:"); 92 num = sc.nextInt(); 93 System.out.println("请输入产生四则运算的范围(最小值和最大值)"); 94 min = sc.nextInt(); 95 max = sc.nextInt(); 96 sum = score(num, min, max); 97 System.out.println("考试结束,最后得分为:" + sum); 98 } 99 }
以上是关于考试系统的主要内容,如果未能解决你的问题,请参考以下文章