1.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;}public void register() {isRegistered = true;System.out.println(stuName + "已完成报到注册");}public void payFee() {if (money >= 6000) {money -= 6000;System.out.println(stuName + "已支付学费,剩余存款:" + money + "元");} else {System.out.println(stuName + "的存款不足,无法支付学费。");}}
}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;}public void registerStudent(String studentName) {if (studentCount < maxCapacity) {studentCount++;studentRoster.add(studentName);System.out.println(studentName + "已注册到班级" + className);} else {System.out.println("班级" + className + "已满员,无法注册更多学生。");}}public void printRoster() {System.out.println("班级" + className + "的花名册:");for (String student : studentRoster) {System.out.println(student);}}
}3.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;}
}4.StudentDemo.java
package Message;
public class StudentDemo {public static void main(String[] args) {// 创建学校对象School school = new School("xxx", "xxx",1978, "xxx", 21000);// 创建班级对象Class classA = new Class("计算机科学与技术", 60, "王老师");// 创建学生对象Student student1 = new Student("xx", 10000, "2021",20, "xxx", "18827014004", "计算机科学与技术", "2021");Student student2 = new Student("李华", 10000, "22006JS4204",19, "xxxx", "18827014003", "计算机科学与技术", "2021");// 输出学校信息System.out.println("学校信息:");System.out.println("校名: " + school.getUniversityName());System.out.println("校址: " + school.getUniversityLocation());System.out.println("创校年份: " + school.getYearFounded());System.out.println("校长姓名: " + school.getDeanName());System.out.println("学校容量: " + school.getStudentCapacity());// 输出班级信息System.out.println("\n班级信息:");System.out.println("班级名: " + classA.getClassName());System.out.println("班主任姓名: " + classA.getTeacherName());System.out.println("班级容量: " + classA.getMaxCapacity());// 学生注册student1.register();student2.register();// 学生支付学费student1.payFee();student2.payFee();// 输出学生信息System.out.println("\n学生信息:");System.out.println("学生1姓名: " + student1.getStuName());System.out.println("学生1年龄:"+student1.getAge());System.out.println("学生1地址: "+student1.getAddress());System.out.println("学生1电话号码: "+student1.getPhoneNumber());System.out.println("学生1存款余额: " + student1.getMoney());System.out.println("学生1是否已注册: " + student1.isRegistered());System.out.println("学生1是否已入学: " + student1.isEnrolled());System.out.println("学生1专业:"+student1.getMajor());System.out.println("学生1学号:"+student1.getStudentID());System.out.println("学生1入学年份:"+student1.getAdmissionYear());System.out.println("\n学生2姓名: " + student2.getStuName());System.out.println("学生2年龄:"+student2.getAge());System.out.println("学生2地址: "+student2.getAddress());System.out.println("学生2电话号码: "+student2.getPhoneNumber());System.out.println("学生2存款余额: " + student2.getMoney());System.out.println("学生2是否已注册: " + student2.isRegistered());System.out.println("学生2是否已入学: " + student2.isEnrolled());System.out.println("学生2专业:"+student2.getMajor());System.out.println("学生2学号:"+student2.getStudentID());System.out.println("学生2入学年份:"+student2.getAdmissionYear());}}