This site requires JavaScript, please enable it in your browser!
Greenfoot back
divinity
divinity wrote ...

2017/6/9

constructor doctor in class doctor cannot be applied to given types

divinity divinity

2017/6/9

#
hi danpost how are you. I am doing this hospital program that involves doing a GUI. it has lot of inheritance, composition, encapsulation and abstraction in it. I have covered all of that except the polymorphism part. The problem that i am having is in some of the class I keep getting this error: in the job class, it says constructor Exchange in the class Exchange cannot be given type. in the dermatologist class it says constructor Doctor in the class Doctor cannot be given type. in the cardiologist class it says constructor Doctor in the class Doctor cannot be given type. here is the codes
This is the cardiologist class which extends doctor
public class Cardiologist extends Doctor {
    
    private int  numofSurgeries;
    private int yrsinPractice;
    private String licenseNo;
    private String medSchool;
    private String courses;
    private Job job;
   
    
    public Cardiologist(String firstName, String lastName, Date_of_Birth dob, String licenseNo, String medSchool, String courses, Job job){
        super(firstName, lastName,dob);
        this.licenseNo = licenseNo;
        this.medSchool = medSchool;
        this.job = job;
        this.courses = courses;
    }
    
    public Job getJob(){
        return job;
    }
    
    @Override
    public String getlicenseNo(){
        return licenseNo;
    }
    
    @Override
    public String getmedSchool(){
        return medSchool;
    }
    public int numofSurgeries(){
        return numofSurgeries;
    }
    public int getyrsinPractice(){
        return yrsinPractice;
    }
    public void setJob(Job job){
        this.job = job;
    }
    public void setlicenseNo(String licenseNo){
        this.licenseNo = licenseNo;
    }
    public void setmedSchool(String medSchool){
        this.medSchool = medSchool;
    }
    public void setnumofSurgeries(int numofSurgeries){
        this.numofSurgeries = numofSurgeries;
    }
    public void setyrsinPractice(int yrsinPractice){
        this.yrsinPractice = yrsinPractice;
    }
    @Override
    public String toString(){
       
        return super.toString() + "Number of Surgeries"+numofSurgeries+ 
                                                    "Years in Practice"+yrsinPractice+
                                                    "Job"+job+"License Number"+licenseNo+
                                                    "Medical School"+ medSchool;      
        
    }

this is the dematologist class which also extends doctor
public class Dermatologist extends Doctor {
    
    private String hrsofwrk;
    
    public Dermatologist(String firstName, String lastName, Date_of_Birth dob){
        
        super(firstName,lastName,dob);
}
    public String gethrsofwrk(){
        return hrsofwrk;
    }
    public void sethrswrk(String hrsofwrk){
        this.hrsofwrk = hrsofwrk;
    }
    @Override
     public String toString(){
        
         String getdetails = "Hours of Work"+hrsofwrk;
         
         return getdetails;
    }

}
this is the job class which extends the exchange class
public class Job  extends Exchange{
    
    private String role;
    private double salary;
    private Visa visa;
    private Job job;
    
   public Job(String role, double salary, Visa visa, Job job ){
       
       this.role = role;
       this.salary = salary;
       this.job = job;
       this.visa = visa;
   }
    
    public String getrole(){
        return role;
    }
    
    public double getsalary(){
        return salary;
    }
    
    public void setrole(String role){
        this.role = role;
    }
    
    public void setsalary(double salary){
        this.salary = salary;
    }
    public String toString(){
        
        String getdetails ="Role"+role+"Salary" +salary;
        
        return getdetails;
    }

this is the exchange class which extends the students class

 */
public class Exchange  extends Student{
    
    private Job job;
    private Visa visa;    
    
    public Exchange(Job job, Visa visa){
        this.job = job;
        this.visa = visa;        
    }
    
    public Job getjob(){
        return job;
    }
    
    public Visa getvisa(){
        return visa;
    }
    
    public void setjob(Job job){
        this.job = job;
    }
    
    public void setvisa(Visa visa){
        this.visa = visa;
    }
    this is the doctor class which extends the person class and where the cardiologiest and dermatologist classes extends

public  abstract class Doctor extends Person {
    
    private String medSchool;
    private String licenseNo;
    private String courses;   
    private Job job;
    
    public Doctor(String firstName, String lastName, Date_of_Birth  dob, String medSchool, String licenseNo, Job job, String courses){
        super(firstName,lastName, dob);
        this.medSchool = medSchool;
        this.licenseNo = licenseNo;
        this.job = job;
        this.courses = courses;
    }
    public String getmedSchool(){
        return medSchool;
    }
    public String getlicenseNo(){
        return licenseNo;
    }
    public String getcourses(){
        return courses;
    }
    public void setmedSchool(String medSchool){
        this.medSchool = medSchool;
    }
    public void setlicenseNo(String licenseNo){
        this.licenseNo = licenseNo;
    }
    public void setcourses(String courses){
        this.courses = courses;
    }
    @Override
    public String toString(){
        return super.toString()+ "\n "+"Medical School"+ medSchool +
                                         "License Number"+licenseNo + 
                                         "Courses"+courses+"Job"+job;
                                         
        
       
    }
Super_Hippo Super_Hippo

2017/6/9

#
Lines 13 and 71
super(firstName,lastName,dob);
try to call a constructor in their super class Doctor with the parameters (String, String, Date_of_Birth). However, there is not such a constructor in the Doctor class. There is only the (String, String, Date_of_Birth, String, String, Job, String) constructor so you are getting this error. You could add this:
public Doctor(String firstName, String lastName, Date_of_Birth dob)
{
    super(firstName,lastName,dob);
}
divinity divinity

2017/6/9

#
thank you very much Super_Hippo what you have suggested to do, it work, thanks sssssssoooooo much. it is well appreciated, now all I have to do is the connected the administrative class to the gui.
You need to login to post a reply.