定义一个学生类(Student),属性包括:学号,班号,姓名,性别,年龄,班级总人数

2024-11-27 14:18:32
推荐回答(1个)
回答1:

public class Test
{
public static void main (String[] args) {
Student[] students = new Student[] {
new Student("123", "456", "abc", "male", 10, 20),
new Student("789", "000", "def", "female", 30, 40)
};
for (Student s : students) {
System.out.println(s);
}
}

}

class Student {
String studentId, classId, name, gender;
int age, studentCount;

public Student(String studentId, String classId, String name,
String gender, int age, int studentCount) {
this.studentId = studentId;
this.classId = classId;
this.name = name;
this.gender = gender;
this.age = age;
this.studentCount = studentCount;
}

public String getStudentId() {
return studentId;
}

public void setStudentId(String studentId) {
this.studentId = studentId;
}

public String getClassId() {
return classId;
}

public void setClassId(String classId) {
this.classId = classId;
}

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 getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public int getStudentCount() {
return studentCount;
}

public void setStudentCount(int studentCount) {
this.studentCount = studentCount;
}

@Override
public String toString() {
return "Student [studentId=" + studentId + ", classId=" + classId
+ ", name=" + name + ", gender=" + gender + ", age=" + age
+ ", studentCount=" + studentCount + "]";
}
}