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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
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
1
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:
1
2
3
4
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.