宿舍管理系统代码
时间: 2023-07-30 14:06:43 浏览: 90
学生宿舍管理系统代码
由于宿舍管理系统较为复杂,涉及多个模块和功能,因此无法提供完整的代码。但是,我可以提供一些常用的Java类和方法,供您参考。
1. 学生信息类(Student):
```
public class Student {
private String name;
private String id;
private String gender;
private String dormNumber;
public Student(String name, String id, String gender) {
this.name = name;
this.id = id;
this.gender = gender;
}
public String getName() {
return name;
}
public String getId() {
return id;
}
public String getGender() {
return gender;
}
public String getDormNumber() {
return dormNumber;
}
public void setDormNumber(String dormNumber) {
this.dormNumber = dormNumber;
}
}
```
2. 宿舍信息类(Dorm):
```
public class Dorm {
private String dormNumber;
private int capacity;
private int currentOccupancy;
private List<Student> students;
public Dorm(String dormNumber, int capacity) {
this.dormNumber = dormNumber;
this.capacity = capacity;
this.currentOccupancy = 0;
this.students = new ArrayList<>();
}
public String getDormNumber() {
return dormNumber;
}
public int getCapacity() {
return capacity;
}
public int getCurrentOccupancy() {
return currentOccupancy;
}
public List<Student> getStudents() {
return students;
}
public void addStudent(Student student) {
if (currentOccupancy < capacity) {
students.add(student);
currentOccupancy++;
student.setDormNumber(dormNumber);
System.out.println("Student " + student.getName() + " has been assigned to dorm " + dormNumber);
} else {
System.out.println("Dorm " + dormNumber + " is already full");
}
}
public void removeStudent(Student student) {
students.remove(student);
currentOccupancy--;
student.setDormNumber(null);
System.out.println("Student " + student.getName() + " has been removed from dorm " + dormNumber);
}
}
```
3. 宿舍管理系统类(DormitoryManagementSystem):
```
public class DormitoryManagementSystem {
private List<Student> students;
private List<Dorm> dorms;
public DormitoryManagementSystem() {
this.students = new ArrayList<>();
this.dorms = new ArrayList<>();
}
public void addStudent(Student student) {
students.add(student);
}
public void addDorm(Dorm dorm) {
dorms.add(dorm);
}
public void assignDorm(Student student) {
for (Dorm dorm : dorms) {
if (dorm.getCurrentOccupancy() < dorm.getCapacity()) {
dorm.addStudent(student);
break;
}
}
}
public void removeStudentFromDorm(Student student) {
for (Dorm dorm : dorms) {
if (dorm.getStudents().contains(student)) {
dorm.removeStudent(student);
break;
}
}
}
}
```
以上是部分代码示例,可以根据具体需求进行改进和完善。
阅读全文