做一个单机的java学生学籍管理系统的课程设计,给出源代码
时间: 2024-01-24 18:17:52 浏览: 81
java开发项目数据库课程设计学生学籍管理系统源代码.zip
5星 · 资源好评率100%
很抱歉,我作为一个语言模型,并不会编写代码。但我可以给你提供一个基本的Java学生学籍管理系统的设计思路:
1. 学生信息类(Student):包含学号、姓名、性别、出生日期、家庭住址、联系电话等属性。
2. 课程信息类(Course):包含课程编号、课程名称、学分、教师名称等属性。
3. 成绩信息类(Score):包含学生学号、课程编号、成绩等属性。
4. 数据存储类(DataStorage):实现学生、课程和成绩信息的存储和查询功能。
5. 用户界面类(UserInterface):提供用户操作界面,包括添加、删除、修改、查询等功能。
6. 主函数类(Main):调用用户界面类,启动程序。
下面是一个简单的Java代码示例,供参考:
```
import java.util.ArrayList;
import java.util.Scanner;
public class StudentManagementSystem {
public static void main(String[] args) {
UserInterface ui = new UserInterface();
ui.start();
}
}
class Student {
private String id;
private String name;
private String gender;
private String birthday;
private String address;
private String tel;
public Student(String id, String name, String gender, String birthday, String address, String tel) {
this.id = id;
this.name = name;
this.gender = gender;
this.birthday = birthday;
this.address = address;
this.tel = tel;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTel() {
return tel;
}
public void setTel(String tel) {
this.tel = tel;
}
}
class Course {
private String id;
private String name;
private int credit;
private String teacher;
public Course(String id, String name, int credit, String teacher) {
this.id = id;
this.name = name;
this.credit = credit;
this.teacher = teacher;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
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;
}
}
class Score {
private String studentId;
private String courseId;
private int score;
public Score(String studentId, String courseId, int score) {
this.studentId = studentId;
this.courseId = courseId;
this.score = score;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getCourseId() {
return courseId;
}
public void setCourseId(String courseId) {
this.courseId = courseId;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
class DataStorage {
private ArrayList<Student> studentList;
private ArrayList<Course> courseList;
private ArrayList<Score> scoreList;
public DataStorage() {
studentList = new ArrayList<Student>();
courseList = new ArrayList<Course>();
scoreList = new ArrayList<Score>();
}
public void addStudent(Student student) {
studentList.add(student);
}
public void deleteStudent(String id) {
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(id)) {
studentList.remove(i);
break;
}
}
}
public void modifyStudent(String id, String name, String gender, String birthday, String address, String tel) {
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(id)) {
studentList.get(i).setName(name);
studentList.get(i).setGender(gender);
studentList.get(i).setBirthday(birthday);
studentList.get(i).setAddress(address);
studentList.get(i).setTel(tel);
break;
}
}
}
public Student findStudent(String id) {
for (int i = 0; i < studentList.size(); i++) {
if (studentList.get(i).getId().equals(id)) {
return studentList.get(i);
}
}
return null;
}
public void addCourse(Course course) {
courseList.add(course);
}
public void deleteCourse(String id) {
for (int i = 0; i < courseList.size(); i++) {
if (courseList.get(i).getId().equals(id)) {
courseList.remove(i);
break;
}
}
}
public void modifyCourse(String id, String name, int credit, String teacher) {
for (int i = 0; i < courseList.size(); i++) {
if (courseList.get(i).getId().equals(id)) {
courseList.get(i).setName(name);
courseList.get(i).setCredit(credit);
courseList.get(i).setTeacher(teacher);
break;
}
}
}
public Course findCourse(String id) {
for (int i = 0; i < courseList.size(); i++) {
if (courseList.get(i).getId().equals(id)) {
return courseList.get(i);
}
}
return null;
}
public void addScore(Score score) {
scoreList.add(score);
}
public void deleteScore(String studentId, String courseId) {
for (int i = 0; i < scoreList.size(); i++) {
if (scoreList.get(i).getStudentId().equals(studentId) && scoreList.get(i).getCourseId().equals(courseId)) {
scoreList.remove(i);
break;
}
}
}
public void modifyScore(String studentId, String courseId, int score) {
for (int i = 0; i < scoreList.size(); i++) {
if (scoreList.get(i).getStudentId().equals(studentId) && scoreList.get(i).getCourseId().equals(courseId)) {
scoreList.get(i).setScore(score);
break;
}
}
}
public Score findScore(String studentId, String courseId) {
for (int i = 0; i < scoreList.size(); i++) {
if (scoreList.get(i).getStudentId().equals(studentId) && scoreList.get(i).getCourseId().equals(courseId)) {
return scoreList.get(i);
}
}
return null;
}
public ArrayList<Student> getStudentList() {
return studentList;
}
public ArrayList<Course> getCourseList() {
return courseList;
}
public ArrayList<Score> getScoreList() {
return scoreList;
}
}
class UserInterface {
private DataStorage ds;
private Scanner input;
public UserInterface() {
ds = new DataStorage();
input = new Scanner(System.in);
}
public void start() {
boolean flag = true;
while (flag) {
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.println("6. 删除课程");
System.out.println("7. 修改课程信息");
System.out.println("8. 查询课程信息");
System.out.println("9. 添加成绩");
System.out.println("10. 删除成绩");
System.out.println("11. 修改成绩信息");
System.out.println("12. 查询成绩信息");
System.out.println("13. 退出系统");
int choice = input.nextInt();
switch (choice) {
case 1:
addStudent();
break;
case 2:
deleteStudent();
break;
case 3:
modifyStudent();
break;
case 4:
findStudent();
break;
case 5:
addCourse();
break;
case 6:
deleteCourse();
break;
case 7:
modifyCourse();
break;
case 8:
findCourse();
break;
case 9:
addScore();
break;
case 10:
deleteScore();
break;
case 11:
modifyScore();
break;
case 12:
findScore();
break;
case 13:
flag = false;
break;
default:
System.out.println("输入错误,请重新选择操作!");
break;
}
}
}
private void addStudent() {
System.out.println("请输入学生信息:");
System.out.print("学号:");
String id = input.next();
System.out.print("姓名:");
String name = input.next();
System.out.print("性别:");
String gender = input.next();
System.out.print("出生日期:");
String birthday = input.next();
System.out.print("家庭地址:");
String address = input.next();
System.out.print("联系电话:");
String tel = input.next();
Student student = new Student(id, name, gender, birthday, address, tel);
ds.addStudent(student);
System.out.println("添加学生成功!");
}
private void deleteStudent() {
System.out.print("请输入要删除的学生学号:");
String id = input.next();
ds.deleteStudent(id);
System.out.println("删除学生成功!");
}
private void modifyStudent() {
System.out.print("请输入要修改的学生学号:");
String id = input.next();
Student student = ds.findStudent(id);
if (student == null) {
System.out.println("该学生不存在!");
} else {
System.out.print("请输入修改后的姓名:");
String name = input.next();
System.out.print("请输入修改后的性别:");
String gender = input.next();
System.out.print("请输入修改后的出生日期:");
String birthday = input.next();
System.out.print("请输入修改后的家庭地址:");
String address = input.next();
System.out.print("请输入修改后的联系电话:");
String tel = input.next();
ds.modifyStudent(id, name, gender, birthday, address, tel);
System.out.println("修改学生信息成功!");
}
}
private void findStudent() {
System.out.print("请输入要查询的学生学号:");
String id = input.next();
Student student = ds.findStudent(id);
if (student == null) {
System.out.println("该学生不存在!");
} else {
System.out.println("学号\t姓名\t性别\t出生日期\t家庭地址\t联系电话");
System.out.println(student.getId() + "\t" + student.getName() + "\t" + student.getGender() + "\t" + student.getBirthday() + "\t" + student.getAddress() + "\t" + student.getTel());
}
}
private void addCourse() {
System.out.println("请输入课程信息:");
System.out.print("课程编号:");
String id = input.next();
System.out.print("课程名称:");
String name = input.next();
System.out.print("学分:");
int credit = input.nextInt();
System.out.print("教师名称:");
String teacher = input.next();
Course course = new Course(id, name, credit, teacher);
ds.addCourse(course);
System.out.println("添加课程成功!");
}
private void deleteCourse() {
System.out.print("请输入要删除的课程编号:");
String id = input.next();
ds.deleteCourse(id);
System.out.println("删除课程成功!");
}
private void modifyCourse() {
System.out.print("请输入要修改的课程编号:");
String id = input.next();
Course course = ds.findCourse(id);
if (course == null) {
System.out.println("该课程不存在!");
} else {
System.out.print("请输入修改后的课程名称:");
String name = input.next();
System.out.print("请输入修改后的学分:");
int credit = input.nextInt();
System.out.print("请输入修改后的教师名称:");
String teacher = input.next();
ds.modifyCourse(id, name, credit, teacher);
System.out.println("修改课程信息成功!");
}
}
private void findCourse() {
System.out.print("请输入要查询的课程编号:");
String id = input.next();
Course course = ds.findCourse(id);
if (course == null) {
System.out.println("该课程不存在!");
} else {
System.out.println("课程编号\t课程名称\t学分\t教师名称");
System.out.println(course.getId() + "\t" + course.getName() + "\t" + course.getCredit() + "\t" + course.getTeacher());
}
}
private void addScore() {
System.out.println("请输入成绩信息:");
System.out.print("学生学号:");
String studentId = input.next();
System.out.print("课程编号:");
String courseId = input.next();
System.out.print("成绩:");
int score = input.nextInt();
Score s = new Score(studentId, courseId, score);
ds.addScore(s);
System.out.println("添加成绩成功!");
}
private void deleteScore() {
System.out.print("请输入要删除成绩的学生学号:");
String studentId = input.next();
System.out.print("请输入要删除成绩的课程编号:");
String courseId = input.next();
ds.deleteScore(studentId, courseId);
System.out.println("删除成绩成功!");
}
private void modifyScore() {
System.out.print("请输入要修改成绩的学生学号:");
String studentId = input.next();
System.out.print("请输入要修改成绩的课程编号:");
String courseId = input.next();
Score score = ds.findScore(studentId, courseId);
if (score == null) {
System.out.println("该成绩不存在!");
} else {
System.out.print("请输入修改后的成绩:");
int newScore = input.nextInt();
ds.modifyScore(studentId, courseId, newScore);
System.out.println("修改成绩信息成功!");
}
}
private void findScore() {
System.out.print("请输入要查询成绩的学生学号:");
String studentId = input.next();
System.out.print("请输入要查询成绩的课程编号:");
String courseId = input.next();
Score score = ds.findScore(studentId, courseId);
if (score == null) {
System.out.println("该成绩不存在!");
} else {
System.out.println("学生学号\t课程编号\t成绩");
System.out.println(score.getStudentId() + "\t" + score.getCourseId() + "\t" + score.getScore());
}
}
}
```
阅读全文