Define two classes, Patient and Billing, whose Objects are records for a clinic. Derive patient from the class person. A class Person has a name, it has methods for setting and getting the name. It also has a function to display the output and a method hasSameName that checks if names are equal. A patient record has the patients name(defined in the class person) and identification number(use the type String). A Billing object will contain a patient object and a doctor object A Doctor record has the doctor’s name—defined in the class Person—a specialty as a string (for example Paediatrician, Obstetrician, General Practitioner, and so on), and an office visit fee (use the type double). Give your Patient and Billing classes a reasonable complement of constructors and accessor methods, and an equal’s method as well. Write a test program that creates at least two patients, at least two doctors and create an array of type Person and process the objects polymorphically. Then create at least two billing records and then displays the total income from the billing records.
This is obviously a HW I'm struggling in, to be specific what should I write in the Billing class? How I am supposed to relate the patient record and billing and doctor record?
To answer your specific question regarding the Billing
class and how you would associate the Patient
and Doctor
, I think your Billing
class might look something like this (to start):
public class Billing {
private Patient p;
private Doctor dr;
public Billing(Patient p, Doctor dr) {
this.p = p;
this.dr = dr;
}
public Doctor getDoctor() {
return dr;
}
public void setDoctor(Doctor newDoctor) {
dr = newDoctor;
}
public Patient getPatient() {
return p;
}
public void setPatient(Patient newPatient) {
p = newPatient;
}
}
I hope that has given you a nudge in the right direction.
EDIT: Code enhanced from first suggestion.