jav定义一个学生类(Student),属性包括:学号,姓名,性别,年龄;方法包括:获得学号,获得姓名,获得性别,获得年龄,修改学号,修改姓名,修改性别,修改年龄。定义并创建一个学生数组对象,长度可自定,最后在控制台输出学生信息。设计程序进行测试。
时间: 2023-06-02 10:01:36 浏览: 376
```java
public class Student {
private String id;
private String name;
private String gender;
private int age;
public Student(String id, String name, String gender, int age) {
this.id = id;
this.name = name;
this.gender = gender;
this.age = age;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
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 class Main {
public static void main(String[] args) {
Student[] students = new Student[3];
students[0] = new Student("001", "张三", "男", 18);
students[1] = new Student("002", "李四", "女", 19);
students[2] = new Student("003", "王五", "男", 20);
for (Student student : students) {
System.out.println("学号:" + student.getId() + ",姓名:" + student.getName() + ",性别:" + student.getGender() + ",年龄:" + student.getAge());
}
}
}
```
阅读全文