java菜鸟求教

来源:百度知道 编辑:UC知道 时间:2024/05/13 17:42:13
有个问题不太明白问的什么,如果可以的话请给我答案,谢谢大家
Consider the following class Student.
public class Student {
protected String name;
protected int student_id;
protected int year;
public Student(String name, int student_id, int year) {
this.name = name;
this.student_id = student_id;
setYear(year);
}
public String toString() {
return "Name: " + name + ", Student Id: " +
student_id + ", Year: " + year;
}
public void setYear(int year) {
if (year > 0 && year <= 3)
this.year = year;
else {
System.out.println("Wrong input! year will be set to 1.");
this.year = 1;
}
}
}
Write a class OutstandingStudent which extends Student. For the class
OutstandingStudent,
a) Add one more attribute award (String),
b) Provide a constructor to initialize the name, student_id, year and award,
c) Override the toString() to return the name, student_

问题是让你继承Student写一个OutstandingStudent类,这个类要多一个award属性,提供一个能初始化四个属性的构造函数,复写toString方法,返回四个属性及其值,最后该题提供了测试类来测试你写的代码是否正确,你的代码输出如果和该测试类输出一值就行了
答案如下:
public class OutstandingStudent extends Student {
protected String award;
public OutstandingStudent (String name, int student_id, int year, String award) {
super(name,student_id,year)
this.award = award;
}
public String toString() {
return "Name: " + name + ", Student Id: " +
student_id + ", Year: " + year + ", Award: " + award;
}
}

Write a class OutstandingStudent which extends Student. For the class
这句话上面给出的是题干 下面提出的是要求 a b c
A test program Test1a is given below.
这句话下面给出的是测试程序 类:"Test1a"
Output: 下面是测试类"Test1a" 的输出结果

我英语也不是特好 你可以把a b c 要求用电子词典翻译过来
a)增加多一个属性 奖(字符串),
b)提供一个构造函数以初始化的名称,student_id,year and award,
三)覆盖toString()返回的名称,studen