pta java 7-8 设计一个学生类
时间: 2023-06-02 09:03:54 浏览: 314
好的,很高兴为您解答。以下是一个简单的学生类的设计,包括学生的姓名、年龄、性别、学号和成绩:
```java
public class Student {
private String name;
private int age;
private String gender;
private String studentNumber;
private double score;
public Student(String name, int age, String gender, String studentNumber, double score) {
this.name = name;
this.age = age;
this.gender = gender;
this.studentNumber = studentNumber;
this.score = score;
}
// getter and setter methods for all the attributes
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getStudentNumber() {
return studentNumber;
}
public void setStudentNumber(String studentNumber) {
this.studentNumber = studentNumber;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
// toString method to print out the attributes of a student
@Override
public String toString() {
return "Name: " + name + ", Age: " + age + ", Gender: " + gender + ", Student Number: " + studentNumber + ", Score: " + score;
}
}
```
以上是一个简单的学生类的设计,可以根据实际需要进行修改和扩展。希望对您有所帮助。
阅读全文