请按照图中要求完成学生信息管理系统设计,程序运行参考效果图如下:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| package me.feihong.model;
public class Subject { private String subjectName; private String subjectNo; private int subjectLife; private Student[] myStudents; private int studentNum;
public Subject() {
}
public Subject(String subjectName, String subjectNo, int subjectLife) { this.setSubjectName(subjectName); this.setSubjectNo(subjectNo); this.setSubjectLife(subjectLife); }
public Subject(String subjectName, String subjectNo, int subjectLife,Student[] myStudents) { this.setSubjectName(subjectName); this.setSubjectNo(subjectNo); this.setSubjectLife(subjectLife); this.setMyStudents(myStudents); }
public void setSubjectName(String subjectName) { this.subjectName = subjectName; }
public String getSubjectName() { return this.subjectName; }
public void setSubjectNo(String subjectNo) { this.subjectNo = subjectNo; }
public String getSubjectNo() { return this.subjectNo; }
public void setSubjectLife(int subjectLife) { if (subjectLife <= 0) return; this.subjectLife = subjectLife; }
public Student[] getMyStudents() { if(this.myStudents==null) this.myStudents=new Student[200]; return myStudents; }
public void setMyStudents(Student[] myStudents) { this.myStudents = myStudents; }
public int getStudentNum() { return studentNum; }
public void setStudentNum(int studentNum) { this.studentNum = studentNum; }
public int getSubjectLife() { return this.subjectLife; }
public String info() { String str = "专业信息如下: \n专业名称:" + this.getSubjectName() + "\n专业编号:" + this.getSubjectNo() + "\n学制年限:" + this.getSubjectLife() + "年"; return str; }
public void addStudent(Student stu) {
int i; for(i=0;i<this.getMyStudents().length;i++) { if(this.getMyStudents()[i]==null) { stu.setStudentSubject(this); this.getMyStudents()[i]=stu; break; } } this.studentNum=i+1; }
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
| package me.feihong.model;
public class Student { private String studentNo; private String studentName; private String studentSex; private int studentAge; private Subject studentSubject;
public Student() {
}
public Student(String studentNo, String studentName, String studentSex, int studentAge) { this.setStudentNo(studentNo); this.setStudentName(studentName); this.setStudentSex(studentSex); this.setStudentAge(studentAge); }
public Student(String studentNo, String studentName, String studentSex, int studentAge, Subject studentSubject) { this.setStudentNo(studentNo); this.setStudentName(studentName); this.setStudentSex(studentSex); this.setStudentAge(studentAge); this.setStudentSubject(studentSubject); }
public Subject getStudentSubject() { if (this.studentSubject == null) this.studentSubject = new Subject(); return studentSubject; }
public void setStudentSubject(Subject studentSubject) { this.studentSubject = studentSubject; }
public String getStudentNo() { return studentNo; }
public void setStudentNo(String studentNo) { this.studentNo = studentNo; }
public String getStudentName() { return studentName; }
public void setStudentName(String studentName) { this.studentName = studentName; }
public String getStudentSex() { return studentSex; }
public void setStudentSex(String studentSex) { if (studentSex == "男" || studentSex == "女") this.studentSex = studentSex; else this.studentSex = "男"; }
public int getStudentAge() { return studentAge; }
public void setStudentAge(int studentAge) { if (studentAge < 10 || studentAge > 100) this.studentAge = 18; else this.studentAge = studentAge; }
public String introduction() { String str = "学生信息如下:\n姓名" + this.getStudentName() + "\n学号:" + this.getStudentNo() + "\n性别:" + this.getStudentSex() + "\n年龄" + this.getStudentAge() + "\n所报专业名称:" + this.getStudentSubject().getSubjectName() + "\n学制年限:" + this.getStudentSubject().getSubjectLife() + "\n专业编号:" + this.getStudentSubject().getSubjectNo(); return str; }
public String introduction(String subjectName, int subjectLife) { String str = "学生信息如下:\n姓名" + this.getStudentName() + "\n学号:" + this.getStudentNo() + "\n性别:" + this.getStudentSex() + "\n年龄" + this.getStudentAge() + "\n所报专业名称:" + subjectName + "\n学制年限:" + subjectLife; return str; }
public String introduction(Subject mySubject) { String str = "学生信息如下:\n姓名" + this.getStudentName() + "\n学号:" + this.getStudentNo() + "\n性别:" + this.getStudentSex() + "\n年龄" + this.getStudentAge() + "\n所报专业名称:" + mySubject.getSubjectName() + "\n学制年限:" + mySubject.getSubjectLife() + "\n专业编号:" + mySubject.getSubjectNo(); return str; }
}
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| package me.feihong.test; import me.feihong.model.*; public class SchoolTest {
public static void main(String[] args) { Subject sub1=new Subject("计算机科学与应用","j0001",4); System.out.println(sub1.info()); System.out.println("============================"); Student stu1=new Student("S01","张三","男",18,sub1); System.out.println(stu1.introduction()); System.out.println("============================"); Student stu2=new Student("S02","李四","女",17); System.out.println(stu2.introduction("计算机科学与应用", 4)); System.out.println("============================"); Student stu3=new Student("S03","王五","男",18); System.out.println(stu3.introduction(sub1)); System.out.println("============================"); sub1.addStudent(stu1); sub1.addStudent(stu2); sub1.addStudent(stu3); System.out.println(sub1.getSubjectName()+"的专业中已有"+sub1.getStudentNum()+"学生进行了报名"); }
}
|