创建一个Student类,有学院,班级,学号,姓名,性别,楼号,房间号,面积,所容纳人数,已入住的Java代码
时间: 2024-05-04 10:19:09 浏览: 79
设计一个学生类Student(学生学号、姓名、数学、英语、计算机成绩;)
5星 · 资源好评率100%
以下是一个简单的示例代码:
```java
public class Student {
private String college;
private String className;
private String studentNumber;
private String name;
private String gender;
private String building;
private String roomNumber;
private double area;
private int capacity;
private boolean isOccupied;
public Student(String college, String className, String studentNumber, String name, String gender, String building, String roomNumber, double area, int capacity, boolean isOccupied) {
this.college = college;
this.className = className;
this.studentNumber = studentNumber;
this.name = name;
this.gender = gender;
this.building = building;
this.roomNumber = roomNumber;
this.area = area;
this.capacity = capacity;
this.isOccupied = isOccupied;
}
// getter and setter methods
// ...
public static void main(String[] args) {
Student student = new Student("Engineering", "2022", "001", "John", "Male", "A", "101", 12.5, 4, true);
System.out.println(student.getName() + " has moved into room " + student.getRoomNumber() + " in building " + student.getBuilding() + ".");
}
}
```
这里我们定义了一个 `Student` 类,包含学院、班级、学号、姓名、性别、楼号、房间号、面积、所容纳人数和是否已入住等属性。在 `main` 方法中,我们创建了一个 `Student` 对象,并打印出该学生已入住的房间信息。
阅读全文