用Java写一个学式管理系统详细
时间: 2024-04-30 13:20:31 浏览: 16
一个学式管理系统需要一些基本功能,例如学生信息管理、课程信息管理、成绩管理等。下面是一个简单的Java实现:
1. 创建一个学生类(Student),包含学生的基本信息,如姓名、学号、性别等:
```
public class Student {
private String name;
private String id;
private String gender;
// 其他属性
public Student(String name, String id, String gender) {
this.name = name;
this.id = id;
this.gender = gender;
}
// getter和setter方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
}
```
2. 创建一个课程类(Course),包含课程的基本信息,如课程名称、学分、教师等:
```
public class Course {
private String name;
private int credit;
private String teacher;
// 其他属性
public Course(String name, int credit, String teacher) {
this.name = name;
this.credit = credit;
this.teacher = teacher;
}
// getter和setter方法
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCredit() {
return credit;
}
public void setCredit(int credit) {
this.credit = credit;
}
public String getTeacher() {
return teacher;
}
public void setTeacher(String teacher) {
this.teacher = teacher;
}
}
```
3. 创建一个成绩类(Score),包含学生、课程和成绩等信息:
```
public class Score {
private Student student;
private Course course;
private double score;
public Score(Student student, Course course, double score) {
this.student = student;
this.course = course;
this.score = score;
}
// getter和setter方法
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public Course getCourse() {
return course;
}
public void setCourse(Course course) {
this.course = course;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
```
4. 创建一个学生管理类(StudentManager),包含添加和查询学生信息的方法:
```
import java.util.ArrayList;
import java.util.List;
public class StudentManager {
private List<Student> students;
public StudentManager() {
students = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public Student getStudent(String id) {
for (Student student : students) {
if (student.getId().equals(id)) {
return student;
}
}
return null;
}
}
```
5. 创建一个课程管理类(CourseManager),包含添加和查询课程信息的方法:
```
import java.util.ArrayList;
import java.util.List;
public class CourseManager {
private List<Course> courses;
public CourseManager() {
courses = new ArrayList<>();
}
public void addCourse(Course course) {
courses.add(course);
}
public Course getCourse(String name) {
for (Course course : courses) {
if (course.getName().equals(name)) {
return course;
}
}
return null;
}
}
```
6. 创建一个成绩管理类(ScoreManager),包含添加和查询成绩信息的方法:
```
import java.util.ArrayList;
import java.util.List;
public class ScoreManager {
private List<Score> scores;
public ScoreManager() {
scores = new ArrayList<>();
}
public void addScore(Score score) {
scores.add(score);
}
public Score getScore(String id, String name) {
for (Score score : scores) {
if (score.getStudent().getId().equals(id) && score.getCourse().getName().equals(name)) {
return score;
}
}
return null;
}
}
```
7. 创建一个测试类(Test),用于测试学生管理、课程管理和成绩管理类的方法:
```
public class Test {
public static void main(String[] args) {
// 添加学生信息
Student student1 = new Student("张三", "1001", "男");
Student student2 = new Student("李四", "1002", "女");
StudentManager studentManager = new StudentManager();
studentManager.addStudent(student1);
studentManager.addStudent(student2);
// 添加课程信息
Course course1 = new Course("Java程序设计", 3, "王五");
Course course2 = new Course("数据结构", 4, "赵六");
CourseManager courseManager = new CourseManager();
courseManager.addCourse(course1);
courseManager.addCourse(course2);
// 添加成绩信息
Score score1 = new Score(student1, course1, 90);
Score score2 = new Score(student1, course2, 80);
Score score3 = new Score(student2, course1, 85);
Score score4 = new Score(student2, course2, 95);
ScoreManager scoreManager = new ScoreManager();
scoreManager.addScore(score1);
scoreManager.addScore(score2);
scoreManager.addScore(score3);
scoreManager.addScore(score4);
// 查询学生信息
Student student = studentManager.getStudent("1001");
System.out.println("姓名:" + student.getName() + ",学号:" + student.getId() + ",性别:" + student.getGender());
// 查询课程信息
Course course = courseManager.getCourse("Java程序设计");
System.out.println("课程名称:" + course.getName() + ",学分:" + course.getCredit() + ",教师:" + course.getTeacher());
// 查询成绩信息
Score score = scoreManager.getScore("1001", "Java程序设计");
System.out.println("学生姓名:" + score.getStudent().getName() + ",课程名称:" + score.getCourse().getName() + ",成绩:" + score.getScore());
}
}
```
这个学式管理系统还可以进一步完善,例如添加修改和删除学生、课程和成绩信息的方法,以及统计学生成绩等功能。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)