实验目标
本实验任务是实现
Java
类的设计和实现,实验任务是根据每年新生的报到流程, 设计一
个学生管理系统,实现学生的注册和报到功能。设置类的基本属性,实现
getter
和
setter
方
法,通过
set
方法设置某个属性后,并且在控制台中利用
get
方法输出显示。学生类的
Register
方法和
PayFee
方法实现学生的报到注册和支付学费功能,
1.
在调用
Register
方法后,班级类中的学生人数增加
1
人,将学生名字增加
学生花名册(使用自己的名字),打印出自己的花名册。
2.
学生的初始存款金额设置为
10000
元,在调用
PayFee
方法后,将学生自己
的存款减去
6000
元,实现剩余金额的控制台打印。
1.School.java
package Message;
public class School {
private String universityName; // 校名
private String universityLocation; // 校址
private int yearFounded; // 创校年份
private String deanName; // 校长姓名
private int studentCapacity; // 学校容量
// 构造方法
public School(String universityName, String universityLocation,
int yearFounded, String deanName, int studentCapacity) {
this.universityName = universityName;
this.universityLocation = universityLocation;
this.yearFounded = yearFounded;
this.deanName = deanName;
this.studentCapacity = studentCapacity;
}
// Getter 和 Setter 方法
public String getUniversityName() {
return universityName;
}
public void setUniversityName(String universityName) {
this.universityName = universityName;
}
public String getUniversityLocation() {
return universityLocation;
}
public void setUniversityLocation(String universityLocation) {
this.universityLocation = universityLocation;
}
public int getYearFounded() {
return yearFounded;
}
public void setYearFounded(int yearFounded) {
this.yearFounded = yearFounded;
}
public String getDeanName() {
return deanName;
}
public void setDeanName(String deanName) {
this.deanName = deanName;
}
public int getStudentCapacity() {
return studentCapacity;
}
public void setStudentCapacity(int studentCapacity) {
this.studentCapacity = studentCapacity;
}
}
2.Class.java
package Message;
import java.util.ArrayList;
public class Class {
private String className; // 班级名
private int studentCount; // 学生人数
private ArrayList<String> studentRoster; // 学生花名册
private int maxCapacity; // 班级最大容量
private String teacherName; // 班主任姓名
// 构造方法
public Class(String className, int maxCapacity, String teacherName) {
this.className = className;
this.studentCount = 0;
this.studentRoster = new ArrayList<>();
this.maxCapacity = maxCapacity;
this.teacherName = teacherName;
}
// Getter 和 Setter 方法
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public int getStudentCount() {
return studentCount;
}
public void setStudentCount(int studentCount) {
this.studentCount = studentCount;
}
public int getMaxCapacity() {
return maxCapacity;
}
public void setMaxCapacity(int maxCapacity) {
this.maxCapacity = maxCapacity;
}
public String getTeacherName() {
return teacherName;
}
public void setTeacherName(String teacherName) {
this.teacherName = teacherName;
}
3.Student.java
package Message;
public class Student {
private String stuName; // 姓名
private int money; // 存款余额
private String studentID; // 学号
private int age; // 年龄
private String address; // 地址
private String phoneNumber; // 电话号码
private String major; // 专业
private String admissionYear; // 入学年份
private boolean isRegistered; // 是否已注册
private boolean isEnrolled; // 是否已入学
// 构造方法
public Student(String stuName, int money, String studentID, int age, String address, String phoneNumber, String major, String admissionYear) {
this.stuName = stuName;
this.money = money;
this.studentID = studentID;
this.age = age;
this.address = address;
this.phoneNumber = phoneNumber;
this.major = major;
this.admissionYear = admissionYear;
this.isRegistered = true;
this.isEnrolled = true;
}
// Getter 和 Setter 方法
public String getStuName() {
return stuName;
}
public void setStuName(String stuName) {
this.stuName = stuName;
}
public int getMoney() {
return money;
}
public void setMoney(int money) {
this.money = money;
}
public String getStudentID() {
return studentID;
}
public void setStudentID(String studentID) {
this.studentID = studentID;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
public String getAdmissionYear() {
return admissionYear;
}
public void setAdmissionYear(String admissionYear) {
this.admissionYear = admissionYear;
}
public boolean isRegistered() {
return isRegistered;
}
public void setRegistered(boolean registered) {
isRegistered = registered;
}
public boolean isEnrolled() {
return isEnrolled;
}
public void setEnrolled(boolean enrolled) {
isEnrolled = enrolled;
}
}