JAVA初学者编程问题

来源:百度知道 编辑:UC知道 时间:2024/06/17 19:14:49
创建一个Student类,在该类中添加三个构造方法,第一个构造方法是一个不传递任何参数的空的构造方法,第二个构造方法传递Student的姓名(name)和学号(StudentID),第三个构造方法传递Student的姓名(name)、学号(StudentID)和年龄(age),并在该类中添加一个main函数,在该函数中用三个构造方法分别添加三个对象,打印输出学生的信息。 麻烦一下编程完了以后能在JAVA那个软件上没有错误的运行,谢谢了

public class Student
{
private String name;
private String studentID;
private int age;
//Contructor
public Student(){}
public Student(String name, String studentID)
{
this.name=name;
this.studentID=studentID;
}
public Student(String name, String studentID, int age)
{
this.name=name;
this.studentID=studentID;
this.age=age;
}
//getters and setters
public void setName(String name)
{
this.name=name;
}
public void setStudentID(String studentID)
{
this.studentID=studentID;
}
public void setAge(int age)
{
this.age=age;
}
public String getName()
{
return this.name;
}
public String getStudentID()
{
return this.studentID;
}
public int getAge()
{
return this.age;
}
//print information
public void printInfo()
{
S