根据三角形的代码示例,自行编写代码实现如下描述的功能的代码: (1)编写一个 StudentBean 类,在其中定义的学生属性有学号、姓名、性别、籍 贯、年龄、专业,各属性的命名按照 Java 命名
时间: 2024-11-25 14:32:24 浏览: 19
当然,我可以帮你编写一个简单的 `StudentBean` 类。这个类会包含你提到的各种学生属性,并提供相应的getter和setter方法。以下是代码示例:
```java
public class StudentBean {
// 定义学生属性
private String studentId;
private String name;
private String gender;
private String hometown;
private int age;
private String major;
// 构造函数
public StudentBean(String studentId, String name, String gender, String hometown, int age, String major) {
this.studentId = studentId;
this.name = name;
this.gender = gender;
this.hometown = hometown;
this.age = age;
this.major = major;
}
// 获取方法
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 String getHometown() {
return hometown;
}
public void setHometown(String hometown) {
this.hometown = hometown;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getMajor() {
return major;
}
public void setMajor(String major) {
this.major = major;
}
// 重写toString方法,以便于打印学生信息
@Override
public String toString() {
return "StudentBean{" +
"studentId='" + studentId + '\'' +
", name='" + name + '\'' +
", gender='" + gender + '\'' +
", hometown='" + hometown + '\'' +
", age=" + age +
", major='" + major + '\'' +
'}';
}
}
```
阅读全文