comomomo 2023-04-13 12:06 采纳率: 50%
浏览 202
已结题

求Java学生选修课程系统设计

假定有n门课程,每门课程有:课程编号,课程名称,课程性质(公共课、必修课、选修课),总学时,授课学时,实验或上机学时,学分,开课学期等信息,学生可按要求(如总学分不得少于60)自由选课。试设计选修课程系统,使之能提供以下功能:
1、系统以菜单方式工作
2、课程信息录入功能--输入
3、课程信息浏览功能--输出
4、课程信息查询功能--算法
查询方式
按学分查询
按课程性质查询
5、学生选修课程(可选项)

  • 写回答

4条回答 默认 最新

  • 语言-逆行者 2023-04-13 12:27
    关注

    不知道是否符合,如果不符合,把需要的要求在此基础上说下

    img

    
    import java.util.ArrayList;
    import java.util.Scanner;
    
    class Course {
        String id;
        String name;
        String nature;
        int totalHours;
        int lectureHours;
        int labHours;
        int credit;
        int semester;
    
        public Course(String id, String name, String nature, int totalHours, int lectureHours, int labHours, int credit, int semester) {
            this.id = id;
            this.name = name;
            this.nature = nature;
            this.totalHours = totalHours;
            this.lectureHours = lectureHours;
            this.labHours = labHours;
            this.credit = credit;
            this.semester = semester;
        }
    }
    
    public class CourseSelectionSystem {
        static ArrayList<Course> courses = new ArrayList<>();
        static ArrayList<Course> selectedCourses = new ArrayList<>();
        static Scanner scanner = new Scanner(System.in);
    
        public static void main(String[] args) {
            while (true) {
                System.out.println("选修课程系统");
                System.out.println("1. 课程信息录入");
                System.out.println("2. 课程信息浏览");
                System.out.println("3. 课程信息查询");
                System.out.println("4. 学生选修课程");
                System.out.println("5. 退出系统");
                System.out.print("请选择: ");
                int choice = scanner.nextInt();
                switch (choice) {
                    case 1:
                        addCourse();
                        break;
                    case 2:
                        viewCourses();
                        break;
                    case 3:
                        searchCourses();
                        break;
                    case 4:
                        selectCourse();
                        break;
                    case 5:
                        System.exit(0);
                    default:
                        System.out.println("无效选择");
                }
            }
        }
    
        public static void addCourse() {
            System.out.print("课程编号: ");
            String id = scanner.next();
            System.out.print("课程名称: ");
            String name = scanner.next();
            System.out.print("课程性质 (公共课/必修课/选修课): ");
            String nature = scanner.next();
            System.out.print("总学时: ");
            int totalHours = scanner.nextInt();
            System.out.print("授课学时: ");
            int lectureHours = scanner.nextInt();
            System.out.print("实验或上机学时: ");
            int labHours = scanner.nextInt();
            System.out.print("学分: ");
            int credit = scanner.nextInt();
            System.out.print("开课学期: ");
            int semester = scanner.nextInt();
    
            Course course = new Course(id, name, nature, totalHours, lectureHours, labHours, credit, semester);
            courses.add(course);
        }
    
        public static void viewCourses() {
            for (Course course : courses) {
                System.out.println(course.id + " " + course.name + " " + course.nature + " " + course.totalHours + " " + course.lectureHours + " " + course.labHours + " " + course.credit + " " + course.semester);
            }
        }
    
        public static void searchCourses() {
            System.out.println("1. 按学分查询");
            System.out.println("2. 按课程性质查询");
            System.out.print("请选择查询方式: ");
            int choice = scanner.nextInt();
            if (choice == 1) {
                System.out.print("输入学分: ");
                int credit = scanner.nextInt();
                for (Course course : courses) {
                    if (course.credit == credit) {
                        System.out.println(course.id + " " + course.name + " " + course.nature + " " + course.totalHours + " " + course.lectureHours + " " + course.labHours + " " + course.credit + " " + course.semester);
                    }
                }
            } else if (choice == 2) {
                System.out.print("输入课程性质 (公共课/必修课/选修课): ");
                String nature = scanner.next();
                for (Course course : courses) {
                    if (course.nature.equals(nature)) {
                        System.out.println(course.id + " " + course.name + " " + course.nature + " " + course.totalHours + " " + course.lectureHours + " " + course.labHours + " " + course.credit +course.semester);
                    }
                }
            } else {
                System.out.println("无效选择");
            }
        }
    
        public static void selectCourse() {
            int totalCredit = 0;
            for (Course course : selectedCourses) {
                totalCredit += course.credit;
            }
            if (totalCredit >= 60) {
                System.out.println("已选学分不得少于60");
                return;
            }
            System.out.print("输入课程编号: ");
            String id = scanner.next();
            for (Course course : courses) {
                if (course.id.equals(id)) {
                    selectedCourses.add(course);
                    System.out.println("选课成功");
                    return;
                }
            }
            System.out.println("未找到课程");
        }
    }
    
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 4月21日
  • 已采纳回答 4月13日
  • 创建了问题 4月13日

悬赏问题

  • ¥20 设计一个二极管稳压值检测电路
  • ¥15 内网办公电脑进行向日葵
  • ¥15 如何输入双曲线的参数a然后画出双曲线?我输入处理函数加上后就没有用了,不知道怎么回事去掉后双曲线可以画出来
  • ¥50 WPF Lidgren.Network.Core2连接问题
  • ¥15 soildworks装配体的尺寸问题
  • ¥100 有偿寻云闪付SDK转URL技术
  • ¥30 基于信创PC发布的QT应用如何跨用户启动后输入中文
  • ¥20 非root手机,如何精准控制手机流量消耗的大小,如20M
  • ¥15 远程安装一下vasp
  • ¥15 自己做的代码上传图片时,报错