美文网首页Java代码实例
Java_实例_作业(控制台学生管理系统)

Java_实例_作业(控制台学生管理系统)

作者: Ethan丶Xiao | 来源:发表于2018-04-27 17:59 被阅读0次
    
    import java.util.Arrays;
    import java.util.Scanner;
    
    public class StudentScore {
        static Scanner input = new Scanner(System.in);\
        //学生个数
        static String names[] = new String[2];
        //课程数量
        static int score[][] = new int[names.length][5];
        private static Scanner scan;
        /**
         * names[]长度
         */
        static int LEN = names.length;
        /**
         * score[]长度
         */
        static int SLEN = score.length;
    
        public static void main(String args[]) {
            welcome();
            options();
    
        }
    
        public static void welcome() {
            System.out.println("请输入一个选项:");
            System.out.print("1`输入学生成绩    ");
            System.out.print("2`显示全部学生成绩        ");
            System.out.println("3`查询学生成绩");
            System.out.print("4`求学生总分     ");
            System.out.print("5`显示最高分       ");
            System.out.println("6`显示最低分");
            System.out.print("7`查看平均分     ");
            System.out.println("8`退出系统");
        }
    
        public static void options() {
            System.out.println("请输入您所需查询的选项:");
    
            int num = input.nextInt();
            switch (num) {
            case 1:
                entryResults();
                welcome();
                options();
                break;
            case 2:
                studentInfo();
                options();
                break;
            case 3:
                inquireInfo();
                welcome();
                options();
                break;
            case 4:
                totalScore();
                welcome();
                options();
                break;
            case 5:
                maxScore();
                welcome();
                options();
                break;
            case 6:
                minScore();
                welcome();
                options();
                break;
            case 7:
                avgScore();
                welcome();
                options();
                break;
            case 8:
                System.out.println("bye!");
                System.exit(0);
                break;
            default:
                System.out.println("输入有误,请重新输入:");
                welcome();
                options();
            }
        }
    
        public static void entryResults() {
            for (int i = 0; i < LEN; i++) {
                System.out.println("请输入第" + (i + 1) + "个学生姓名");
                names[i] = input.next();
            }
            for (int i = 0; i < SLEN; i++) {
                for (int j = 0; j < score[i].length; j++) {
                    System.out.println("请录入" + names[i] + "的" + getCoursName(j) + "成绩");
                    score[i][j] = input.nextInt();
                }
            }
            System.out.println("录入完成!");
        }
    
        public static String getCoursName(int i) {
            switch (i) {
            case 0:
                return "数学";
            case 1:
                return "英语";
            case 2:
                return "计算机";
            case 3:
                return "体育";
            case 4:
                return "语文";
            default:
                return "无";
    
            }
        }
    
        public static void studentInfo() {
            System.out.println("显示所有学生信息:");
            System.out.println("姓名\t数学\t英语\t计算机\t体育\t语文");
            for (int i = 0; i < LEN; i++) {
                System.out.println(names[i] + "\t");
                for (int j = 0; j < score[i].length; j++) {
                    System.out.println(score[i][j] + "\t");
                }
            }
        }
    
        public static void inquireInfo() {
            System.out.println("请输入要查询的学生姓名:");
            scan = new Scanner(System.in);
            String name = scan.next();
            for (int i = 0; i < LEN; i++) {
                if (name.equals(names[i])) {
                    for (int j = 0; j < 5; j++) {
                        System.out.println(names[i] + "的 " + getCoursName(j) + "成绩是: " + score[i][j]);
                    }
                }
            }
        }
    
        public static void totalScore() {
            int[] sum = new int[5];
            for (int i = 0; i < LEN; i++) {
                for (int j = 0; j < 5; j++) {
                    sum[j] += score[i][j];
                }
            }
            for (int i = 0; i < 5; i++) {
                System.out.println(getCoursName(i) + "总成绩是: " + sum[i]);
            }
        }
    
        public static void maxScore() {
            for (int i = 0; i < SLEN; i++) {
                Arrays.sort(score[i]);
                System.out.println(names[i] + "最高分是 : " + score[i][score[i].length - 1]);
            }
        }
    
        public static void minScore() {
            for (int i = 0; i < SLEN; i++) {
                Arrays.sort(score[i]);
                System.out.println(names[i] + "最低分是 : " + score[i][0]);
            }
        }
    
        public static void avgScore() {
            int[] nums = new int[LEN];
            for (int i = 0; i < SLEN; i++) {
                for (int j = 0; j < score[i].length; j++) {
                    nums[i] += score[i][j];
                }
            }
            for (int j = 0; j < LEN; j++) {
                System.out.println(names[j] + "平均分是 : " + (nums[j] / score[j].length));
            }
    
        }
    }
    

    相关文章

      网友评论

        本文标题:Java_实例_作业(控制台学生管理系统)

        本文链接:https://www.haomeiwen.com/subject/gjjilftx.html