0

这是一个带有继承和多态方法的java代码。

学生班

public abstract class Student
{
    protected long id;
    protected String name;
    protected String programCode;
    protected int part;

    public Student(){
        id=0;
        name=" ";
        programCode=" ";
        part=0;
    }

    public void setStudent(long i,String nm,String code,int pt){
        id=i;
        name=nm;
        programCode=code;
        part=pt;
    }

    public long getId()            {return id;}    
    public String getName()        {return name;}    
    public String getProgramCode() {return programCode;}    
    public int getPart()           {return part;}    
    public abstract double calculateFees();

    public String toString(){
       return ("ID: "+id+"\nName: "+name+"\nProgram Code: "+programCode+"\nPart: "+part);}
    }

全日制学生班

public class FullTimeStudent extends Student{
    protected String collegeName;
    protected String roomNumber;

public FullTimeStudent(){
    super();
    collegeName=" ";
    roomNumber=" ";
}    
public FullTimeStudent(long i,String nm,String code,int pt,
                              String collegeNm,String roomNum){
    super(i,nm,code,pt); //can't find symbol here
    collegeName=collegeNm;
    roomNumber=roomNum;
}    
public void setFullTimeStudent(String collegeNm,String roomNum){
    collegeName=collegeNm;
    roomNumber=roomNum;
}    
public String getCollegeName()   {return collegeName;}
public String getRoomNumber()    {return roomNumber;}

public double calculateFees(){
    double fee=0, collegefee=0, totalfee=0;

    if(programCode.equals("BIT")){
       fee=2000;
    }
    else if(programCode.equals("BCHE")){
       fee=2300;
    }
    else if(programCode.equals("BPHY")){
       fee=3200;
    } 
    else if(programCode.equals("BBIO"))
       fee=2700;
    } 

    if(collegeName.equals("Jati")){
       collegefee=200;
    }
    else if(collegeName.equals("Cengal")){
       collegefee=350;
    }
    else if(collegeName.equals("Dahlis")){
       collegefee=420;

       totalfee=fee+collegefee;
       return totalfee;
    }

public String toString(){
     return super.toString()+"\nCollege Name: "+collegeName+"\nRoom Number"+roomNumber;
}

}

似乎在 FullTimeStudent 类中找不到 super 语句的符号。

super(i,nm,code,pt); 
4

2 回答 2

1

正如错误试图告诉您的那样,您的超类没有任何带参数的构造函数。

于 2013-09-01T13:43:23.823 回答
1

将 的方法声明更改为Student#setStudent构造函数中预期的重载构造函数的声明FullTimeStudent

protected Student(long i, String nm, String code, int pt) {
    id = i;
    name = nm;
    programCode = code;
    part = pt;
}

然后可以将无参数构造函数简化为

protected Student() {
   this(0, " ", " ", 0);
}

(将文字值转换为预定义常量作为练习)

于 2013-09-01T13:45:12.603 回答