定义一个学生类(Student),属性包括:学号,班号,姓名,性别,年龄,班级总人数
方法包括:获得学号,获得班号,获得姓名,获得性别,获得年龄,获得班级总人数,修改学号,修改班号,修改姓名,修改性别,修改年龄以及一个toString()方法将Studen...
方法包括:获得学号,获得班号,获得姓名,获得性别,获得年龄,获得班级总人数,修改学号,修改班号,修改姓名,修改性别,修改年龄以及一个toString()方法将Student类中的所有属性组合成一个字符串。定义一个学生数组对象。设计程序进行测试。
展开
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 + "]";
}
}
{
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 + "]";
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询