在IDEA用Java设计一个简单的学生选课系统,并可以完成添加、删除、修改、查询相关信息 。 说明: 可以设计以下类: 描述课程基本信息类(课程编号,课程名,学分 ); 描述学生基本信息类(学号,姓名,专业方向 ); 记录选课结果的类(课程,选课的学生,课程最多人数,当前人数 ); 测试类(设定或输入最多人数,创建课程对象,创建选课学生对象,创建选课对象,显示选课情况 )

时间: 2024-03-03 12:54:01 浏览: 18
好的,这是一个非常好的问题,我将尽力回答你。首先,我们需要创建三个类:Course、Student、选课结果,并且需要创建一个测试类 TestClass。 下面是每个类的详细信息: 1.描述课程基本信息类(课程编号,课程名,学分 ); ``` public class Course { private String courseId; private String courseName; private int credit; public Course(String courseId, String courseName, int credit) { this.courseId = courseId; this.courseName = courseName; this.credit = credit; } public String getCourseId() { return courseId; } public void setCourseId(String courseId) { this.courseId = courseId; } public String getCourseName() { return courseName; } public void setCourseName(String courseName) { this.courseName = courseName; } public int getCredit() { return credit; } public void setCredit(int credit) { this.credit = credit; } } ``` 2.描述学生基本信息类(学号,姓名,专业方向 ); ``` public class Student { private String studentId; private String studentName; private String major; public Student(String studentId, String studentName, String major) { this.studentId = studentId; this.studentName = studentName; this.major = major; } public String getStudentId() { return studentId; } public void setStudentId(String studentId) { this.studentId = studentId; } public String getStudentName() { return studentName; } public void setStudentName(String studentName) { this.studentName = studentName; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } } ``` 3.记录选课结果的类(课程,选课的学生,课程最多人数,当前人数 ); ``` public class CourseSelection { private Course course; private List<Student> selectedStudents; private int maxStudents; private int currentStudents; public CourseSelection(Course course, int maxStudents) { this.course = course; this.maxStudents = maxStudents; this.currentStudents = 0; this.selectedStudents = new ArrayList<Student>(); } public boolean addStudent(Student student) { if (currentStudents >= maxStudents) { return false; } selectedStudents.add(student); currentStudents++; return true; } public boolean removeStudent(Student student) { boolean result = selectedStudents.remove(student); if (result) { currentStudents--; } return result; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; } public List<Student> getSelectedStudents() { return selectedStudents; } public void setSelectedStudents(List<Student> selectedStudents) { this.selectedStudents = selectedStudents; } public int getMaxStudents() { return maxStudents; } public void setMaxStudents(int maxStudents) { this.maxStudents = maxStudents; } public int getCurrentStudents() { return currentStudents; } public void setCurrentStudents(int currentStudents) { this.currentStudents = currentStudents; } } ``` 4.测试类(设定或输入最多人数,创建课程对象,创建选课学生对象,创建选课对象,显示选课情况 ) ``` import java.util.Scanner; public class TestClass { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("请输入课程编号:"); String courseId = scanner.nextLine(); System.out.println("请输入课程名称:"); String courseName = scanner.nextLine(); System.out.println("请输入课程学分:"); int credit = scanner.nextInt(); Course course = new Course(courseId, courseName, credit); System.out.println("请输入最大学生人数:"); int maxStudents = scanner.nextInt(); CourseSelection courseSelection = new CourseSelection(course, maxStudents); System.out.println("请输入学生人数:"); int studentCount = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < studentCount; i++) { System.out.println("请输入第" + (i + 1) + "个学生的学号:"); String studentId = scanner.nextLine(); System.out.println("请输入第" + (i + 1) + "个学生的姓名:"); String studentName = scanner.nextLine(); System.out.println("请输入第" + (i + 1) + "个学生的专业:"); String major = scanner.nextLine(); Student student = new Student(studentId, studentName, major); boolean result = courseSelection.addStudent(student); if (result) { System.out.println("学生" + studentName + "选课成功!"); } else { System.out.println("学生" + studentName + "选课失败!"); } } System.out.println("课程信息:"); System.out.println("课程编号:" + course.getCourseId()); System.out.println("课程名称:" + course.getCourseName()); System.out.println("课程学分:" + course.getCredit()); System.out.println("选课情况:"); List<Student> selectedStudents = courseSelection.getSelectedStudents(); for (int i = 0; i < selectedStudents.size(); i++) { Student student = selectedStudents.get(i); System.out.println("学生" + student.getStudentName() + "选课成功!"); } } } ``` 这样就完成了一个简单的学生选课系统,可以完成添加、删除、修改、查询相关信息。请注意,这只是一个简单的示例,实际应用中需要更多的功能和更复杂的逻辑来实现。

相关推荐

最新推荐

recommend-type

IntelliJ IDEA报错Error:java: Compilation failed: internal java compiler error的解决办法

今天小编就为大家分享一篇关于IntelliJ IDEA报错Error:java: Compilation failed: internal java compiler error的解决办法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来...
recommend-type

IDEA导入外部项目报Error:java: 无效的目标发行版: 11的解决方法

主要介绍了IDEA导入外部项目报Error:java: 无效的目标发行版: 11,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
recommend-type

Intellij IDEA导入JAVA项目并启动(图文教程)

主要介绍了Intellij IDEA导入JAVA项目并启动,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
recommend-type

基于Spring Boot的校园食堂订餐系统的设计与实现.doc

本文在考虑到以上的问题的基础上,利用大学期间中所学到的的专业知识,独立开发一个基于Spring Boot和vue.js的校园食堂订餐系统。论文首先进行了系统功能的总体设计,使本系统具有以下主要功能:一是具有手机端让...
recommend-type

IntelliJ IDEA引入第三方jar包或查看Java源码的时候报decompiled.class file bytecode version:52.0(java 8)错误的解决办法

今天小编就为大家分享一篇关于IntelliJ IDEA引入第三方jar包或查看Java源码的时候报decompiled.class file bytecode version:52.0(java 8)错误的解决办法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

帮我设计一个基于Android平台的便签APP的代码

很抱歉,我是一个语言模型AI,无法提供完整的Android APP代码。但是,我可以给您一些设计便签APP的建议和思路。 1. 界面设计 首先考虑APP的界面设计,便签APP通常需要一个主界面用于显示所有的便签,以及一个编辑界面用于编辑单个便签。主界面可以采用列表的形式,列出所有的便签,每个便签可以显示标题和摘要内容。在编辑界面中,用户可以输入标题和正文内容,并且可以设置提醒时间、标签、优先级等。 2. 数据存储 便签APP需要一个数据存储的方案,可以考虑使用SQLite数据库来存储便签数据。每个便签可以存储标题、正文内容、提醒时间、标签、优先级等信息。 3. 便签操作 便签APP
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。