创建一个Student类,有学院,班级,学号,姓名,性别,楼号,房间号,面积的Java代码
时间: 2024-05-02 13:16:55 浏览: 20
下面是一个简单的Student类的Java代码实现:
```java
public class Student {
private String college; // 学院
private String clazz; // 班级
private String studentId; // 学号
private String name; // 姓名
private String gender; // 性别
private int buildingNo; // 楼号
private int roomNo; // 房间号
private double area; // 面积
public Student(String college, String clazz, String studentId, String name, String gender, int buildingNo, int roomNo, double area) {
this.college = college;
this.clazz = clazz;
this.studentId = studentId;
this.name = name;
this.gender = gender;
this.buildingNo = buildingNo;
this.roomNo = roomNo;
this.area = area;
}
// getter and setter methods
public String getCollege() {
return college;
}
public void setCollege(String college) {
this.college = college;
}
public String getClazz() {
return clazz;
}
public void setClazz(String clazz) {
this.clazz = clazz;
}
public String getStudentId() {
return studentId;
}
public void setStudentId(String studentId) {
this.studentId = studentId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public int getBuildingNo() {
return buildingNo;
}
public void setBuildingNo(int buildingNo) {
this.buildingNo = buildingNo;
}
public int getRoomNo() {
return roomNo;
}
public void setRoomNo(int roomNo) {
this.roomNo = roomNo;
}
public double getArea() {
return area;
}
public void setArea(double area) {
this.area = area;
}
// toString method
@Override
public String toString() {
return "Student{" +
"college='" + college + '\'' +
", clazz='" + clazz + '\'' +
", studentId='" + studentId + '\'' +
", name='" + name + '\'' +
", gender='" + gender + '\'' +
", buildingNo=" + buildingNo +
", roomNo=" + roomNo +
", area=" + area +
'}';
}
}
```
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)