各位大虾帮帮小弟,看看这个程序吧!
abstract class Student
输出信息.zip
(20.97 KB)
{
String name;
String type;
float score;
String level;
abstract String GetName();
abstract String GetType();
abstract float GetScore();
abstract String GetLevel();
};
class Undergraduate extends Student{
String GetName(String x){
this.name = x;
}
String GetType(String y){
this.type = y;
}
float GetScore(float a){
this.score = a;
}
String GetLevel(){
if(this.score>=85&&this.score<100)
level = "excellent";
if(this.score<85&&this.score>=75)
level = "good";
if(this.score<75&&this.score>=65)
level = "middle";
if(this.score<65&&this.score>=60)
level = "poor";
if(this.score<60)
level = "fail";
}
public String toString(){
return "Name:"+name+"\nType:"+type+"\nScore:"
+score+"\nLevel:"+level+"\n";
}
};
class Postgraduate extends Student
{
String GetName(String x){
this.name = x;
}
String GetType(String y){
this.type = y;
}
String GetScore(float a){
this.score = a;
}
String GetLevel(){
if(this.score>=90&&this.score<=100)
level = "excellent";
if(this.score<90&&this.score>=80)
level = "good";
if(this.score<80&&this.score>=70)
level = "middle";
if(this.score<70&&this.score>=60)
level = "poor";
if(this.score<60)
level = "fail";
}
public String toString(){
return "Name:"+name+"\nType:"+type+"\nScore:"
+score+"\nLevel:"+level+"\n";
}
};
public class StudentDemo
{
public static void main(String[] args)
{
Undergraduate a = new Undergraduate();
a.GetName("Tom Smith");
a.GetType("Undergraduate");
a.GetScore(85.3f);
a.GetLevel();
System.out.println("As follows,this is some exam information of an undergraduate");
a.toString();
Postgraduate b = new Postgraduate();
b.GetName("Jerry Zhang");
b.GetType("Postgraduate");
b.GetScore(91.3f);
b.GetLevel();
System.out.println("As follows,this is some exam information of a postgraduate");
b.toString();
};
};
//输出提示没有覆盖抽象方法,可我找不到错误啊,我把输出的dos窗口传上去了,请大家帮我看一下吧,谢谢
[ 本帖最后由 ted19910129 于 2011-3-18 10:31 编辑 ]