• Java 学生管理系统


    今天简单练习了一下 数组和循环的一些知识,写了一个小游戏,大致如下

    /**
     * 一个小功能:学生管理系统
     * 1、添加学生信息
     * 2、显示学生信息
     * 3、删除学生信息
     * 4、修改学生信息
     * 5、查看学生信息
     * 6、排序
     * 7、退出
     */
    public class StudentManage {
    
        public static void main(String[] args) {
            Integer[] studentId = new Integer[100];
            Integer[] studentScore = new Integer[100];
            String[] studentName = new String[100];
    
            int mumber = 0;
            Integer studentCount = 0;
            int time = 0;
    
            System.out.println("欢迎进入学生管理系统\n1、添加学生信息\n2、显示学生信息\n3、删除学生西悉尼\n4、修改学生信息\n5、查询学生信息\n6、排序\n7、退出");
            while (true) {
                System.out.println("请输入操作信息:");
                Scanner scanner = new Scanner(System.in);
                int number = scanner.nextInt();
    
                switch (number) {
                    case 1:
                        studentCount = add(studentId, studentName, studentScore, studentCount);
                        System.out.println("添加成功");
                        break;
                    case 2:
                        display(studentId, studentName, studentScore, studentCount);
                        break;
                    case 3:
                        studentCount = delete(studentId, studentName, studentScore, studentCount);
                    case 4:
                        update(studentId, studentName, studentScore, studentCount);
                        break;
                    case 5:
                        select(studentId, studentName, studentScore, studentCount);
                        break;
                    case 6:
                        sort(studentId, studentName, studentScore, studentCount);
                        break;
                    case 7:
                        System.exit(0);
                        break;
                    default:
                        System.out.println("请正确输入(1~7)的数字");
                }
            }
        }
    
        /**
         * 功能描述:添加学生信息
         *
         * @param studentId
         * @param studentName
         * @param studentScore
         * @param studentCount
         * @return
         */
        public static Integer add(Integer[] studentId, String[] studentName, Integer[] studentScore, Integer studentCount) {
            System.out.println("请输入学生ID");
            Scanner scan = new Scanner(System.in);
            studentId[studentCount] = scan.nextInt();
            System.out.println("请输入学习姓名");
            studentName[studentCount] = scan.next();
            System.out.println("请输入学生成绩");
            studentScore[studentCount] = scan.nextInt();
            studentCount++;
            return studentCount;
        }
    
        /**
         * 功能描述: 显示学生信息
         *
         * @param studentId
         * @param studentName
         * @param studentScore
         * @param studentCount
         */
        public static void display(Integer[] studentId, String[] studentName, Integer[] studentScore, Integer studentCount) {
            System.out.println("学号" + "\t姓名" + "\t成绩\n");
            for (int i = 0; i < studentCount; i++) {
                System.out.println(studentId[i] + "\t" + studentName[i] + "\t" + studentScore[i]);
                ;
            }
        }
    
    
        /**
         * 功能描述:删除学生信息
         *
         * @param studentId
         * @param studentName
         * @param studentScore
         * @param studentCount
         * @return
         */
        public static Integer delete(Integer[] studentId, String[] studentName, Integer[] studentScore, Integer studentCount) {
            Integer select = select(studentId, studentName, studentScore, studentCount);
            System.out.println("确定删除学生信息吗?(y/n)");
            Scanner scanner = new Scanner(System.in);
            char next = scanner.next().trim().toLowerCase().charAt(0);
            switch (next) {
                case 'n':
                    System.out.println("您已经需求删除操作了...");
                    break;
                case 'y':
                    for (int i = 0; i < studentCount; i++) {
                        if (i < studentCount - 1) {
                            studentId[i] = studentId[i + 1];
                            studentName[i] = studentName[i + 1];
                            studentScore[i] = studentScore[i + 1];
                        }
                        studentId[i] = null;
                        studentName[i] = null;
                        studentScore[i] = null;
                        return studentCount--;
                    }
            }
            return studentCount;
        }
    
    
        /**
         * 功能描述:查询学生信息
         *
         * @param studentId
         * @param studentName
         * @param studentScore
         * @param studentCount
         * @return
         */
        public static Integer select(Integer[] studentId, String[] studentName, Integer[] studentScore, Integer studentCount) {
            System.out.println("请输入学习姓名");
            Scanner scanner = new Scanner(System.in);
            String queryStudentName = scanner.next();
            for (int i = 0; i < studentCount; i++) {
                if (queryStudentName.trim().equals(studentName[i].trim())) {
                    System.out.println("学号" + "\t姓名" + "\t成绩");
                    System.out.println(studentId[i] + "\t" + studentName[i] + "\t" + studentScore[i]);
                    return studentId[i];
                }
            }
            return null;
        }
    
        /**
         * 功能描述:修改学生信息
         *
         * @param studentId
         * @param studentName
         * @param studentScore
         * @param studentCount
         */
        public static void update(Integer[] studentId, String[] studentName, Integer[] studentScore, Integer studentCount) {
    
            Integer select = select(studentId, studentName, studentScore, studentCount);
            if (select == null) {
                System.out.println("你输入的信息有误,请重新输入");
            } else {
                System.out.println("请输入新学号");
                Scanner scanner = new Scanner(System.in);
                studentId[select] = scanner.nextInt();
                System.out.println("请输入新学生姓名");
                studentName[select] = scanner.next().trim();
                System.out.println("请输入新学生成绩");
                studentScore[select] = scanner.nextInt();
                System.out.println("修改完成");
            }
        }
    
        /**
         * 功能描述: 排序
         *
         * @param studentId
         * @param studentName
         * @param studentScore
         * @param studentCount
         */
        public static void sort(Integer[] studentId, String[] studentName, Integer[] studentScore, Integer studentCount) {
            System.out.println("请选择排序规则:1、按学号排序,2、按成绩排序");
            Scanner scanner = new Scanner(System.in);
            int num = scanner.nextInt();
            switch (num) {
                case 1:
                    for (int i = 0; i < studentCount; i++) {
                        for (int j = 0; j < studentCount - i - 1; j++) {
                            if (studentId[j] > studentId[j + 1]) {
                                int temp = studentId[j];
                                studentId[j] = studentId[j + 1];
                                studentId[j = 1] = temp;
    
                                temp = studentScore[j];
                                studentScore[j] = studentScore[j + 1];
                                studentScore[j + 1] = temp;
    
                                String s = studentName[j];
                                studentName[j] = studentName[j + 1];
                                studentName[j + 1] = s;
                            }
                        }
                    }
                    display(studentId, studentName, studentScore, studentCount);
                    break;
                case 2:
                    for (int i = 0; i < studentCount; i++) {
                        for (int j = 0; j < studentCount - i - 1; j++) {
                            if (studentScore[j] > studentScore[j + 1]) {
                                int temp = studentId[j];
                                studentId[j] = studentId[j + 1];
                                studentId[j = 1] = temp;
    
                                temp = studentScore[j];
                                studentScore[j] = studentScore[j + 1];
                                studentScore[j + 1] = temp;
    
                                String s = studentName[j];
                                studentName[j] = studentName[j + 1];
                                studentName[j + 1] = s;
                            }
                        }
                    }
                    display(studentId, studentName, studentScore, studentCount);
                    break;
                default:
                    System.out.println("输入错误,退出程序");
            }
        }
    }
  • 相关阅读:
    201871010114李岩松《面向对象程序设计(java)》第十二周学习总结
    201871010114李岩松《面向对象程序设计(java)》第十六周学习总结
    201871010114李岩松《面向对象程序设计(java)》第八周学习总结
    201871010114李岩松《面向对象程序设计(java)》第七周学习总结
    201871010114李岩松《面向对象程序设计(java)》第六、七周学习总结
    一分钟秒解数据库三大范式
    反射机制获取类的方法
    hashMap和hashTable的区别
    ssm+maven 框架整合
    Hibernate从零开始的反向工程
  • 原文地址:https://www.cnblogs.com/wdh01/p/16635571.html
Copyright © 2020-2023  润新知