import java.util.Scanner; class Student { private int id; private String name; private int age; private String gender; private double grade; public void setGrade(double grade) { this.grade = grade; } public Stude
时间: 2024-02-14 20:06:57 浏览: 142
这段代码依然不完整,但是我们可以看出这是一个学生类,包含了一些属性和方法。以下是一份完整的学生类代码示例,希望可以帮到您:
```
import java.util.Scanner;
class Student {
private int id;
private String name;
private int age;
private String gender;
private double grade;
public Student() {
this.id = 0;
this.name = "";
this.age = 0;
this.gender = "";
this.grade = 0;
}
public Student(int id, String name, int age, String gender, double grade) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
this.grade = grade;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
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 double getGrade() {
return grade;
}
public void setGrade(double grade) {
this.grade = grade;
}
public void input() {
Scanner sc = new Scanner(System.in);
System.out.print("请输入学号:");
this.id = sc.nextInt();
System.out.print("请输入姓名:");
this.name = sc.next();
System.out.print("请输入年龄:");
this.age = sc.nextInt();
System.out.print("请输入性别:");
this.gender = sc.next();
System.out.print("请输入成绩:");
this.grade = sc.nextDouble();
}
public void output() {
System.out.println("学号:" + this.id);
System.out.println("姓名:" + this.name);
System.out.println("年龄:" + this.age);
System.out.println("性别:" + this.gender);
System.out.println("成绩:" + this.grade);
}
}
```
这是一个比较基础的学生类,包含了一些常见的属性和方法,例如构造函数、getter和setter方法、输入输出方法等。您可以在此基础上进行扩展和修改。
阅读全文