JAVA编写一个学生类的程序

2024-11-27 10:33:50
推荐回答(2个)
回答1:

学生类:
public class Student{
private String name;
private int age;
private double score;
public dd(String name, int age, double score) {
super();
this.name = name;
this.age = age;
this.score = score;
}
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 double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}

public void printInfo()
{
System.out.println("name:"+name);
System.out.println("age:"+age);
System.out.println("score:"+score);
}
} main() 方法:public class TestStudent{
public static void main(String[] args) {
Student stu=new Student("李四",20,89);
stu.printInfo();
}} 友情提示:考试的题目还是应该自己做,尽管就是做错了,那对自己还是很有帮助的

回答2:

先写实体类(学生类):class Student(){ public String name; public int age; public double score; public Student(String name,int age,double score){ this.name=name; this.age=age; this.score=score; } public void printInfo(){ System.out.println("name:"+name+“;age”+age+“;score”+score); } }然后写主程序:class Test(){ public static void main(String [] arges){ Student stu=new Student("黎明",24,100); stu.printInfo(); }}