Give the definition of two classes, Patient and Billing, whose objects are records for a clinic. Patient will be derived from the class Person given in Programming Project 7.6 . A Patient record has the patient’s name (inherited from the class Person) and primary physician of type Doctor defined in Programming Project 7.5 A Billing object will contain a Patient object, a Doctor object, and an amount due of type double. Be sure your classes have a reasonable complement of constructors, accessor, and mutator methods, and suitably defined equals and toString methods. First write a driver program to test all your methods, then write a test program that creates at least two patients, at least two doctors, and at least two Billing records, and then prints out the total income from the Billing records.
Take Project 7.5 and 7.6 code from the text book.
The following codes are Doctor, Person, Patient and Billing classes.
//Doctor.java
public class Doctor extends SalariedEmployee
{
private String speclist;
private double fees;
public Doctor()
public Doctor(String theName, Date theDate, double theSalary, String thespeclist,double theFee)
public Doctor(Doctor otherDoctor)
public void setspeclist(String newspeclist)
public void setfees(double newfees)
public String getspeclist()
public double getfees()
public boolean equals(Doctor other)
public String toString()
}
//Person.java
public class Person
{
private String personName;
public Person()
public Person(String thepersonName)
public Person(Person theObject)
public String getpersonName()
public void setpersonName(String thepersonName)
public String toString()
public boolean equals(Object other)
}
// Patient.java
public class Patient extends Person
{
private Doctor physician;
//Default constructor
public Patient()
{
super();
physician = new Doctor();
}
//Constructor with parameters
public Patient(String name, Doctor aDoctor)
{
super(name);
physician = aDoctor;
}
//method setDocotor
public void setDoctor(Doctor newDoctor)
{
physician = newDoctor;
}
//method Doctor
public Doctor getPhysician()
{
return physician;
}
public String toString()
{
return super.toString() + ", Physician: " + physician.getName();
}
public boolean equals(Patient other)
{
return super.equals(other) &&
physician.equals(other.physician);
}
}
//Billing.java
public class Billing
{
private Patient patient;
private Doctor physician;
private double amount;
//Default constructor
public Billing()
{
patient = new Patient();
physician = new Doctor();
amount = 0;
}
//Constructor with parameters
public Billing(Patient thePatient, Doctor thePhysician,
double amount)
{
patient = thePatient;
physician = thePhysician;
amount = amount;
}
public void setPatient(Patient newPatient)
{
patient = newPatient;
}
public void setPhysician(Doctor newPhysician)
{
physician = newPhysician;
}
public void setamount(double newAmount)
{
amount = newAmount;
}
public Patient getPatient()
{
return patient;
}
public Doctor getPhysician()
{
return physician;
}
public double getamount()
{
return amount;
}
public String toString()
{
return "Patient: " + patient.toString() + ", Physician: " + physician.getName() +
", Fee: $" + amount;
}
public boolean equals(Billing other)
{
return patient.equals(other.patient) &&
physician.equals(other.physician) &&
amount == other.amount;
}
}
//main class, PersonDemo.java
public class PersonDemo {
public static void main(String args[]) {
// Take Date code from Display 4.13 in the text book
// textbook
Doctor p1 = new Doctor("Peter Mark", new Date(4, 30, 1995), 75000, "Physician", 85);
Doctor p2 = new Doctor("Josh Samuel", new Date(2, 12, 1990), 88000, "Physician", 90);
Patient p3 = new Patient("Sam Peter", p1);
Patient p4 = new Patient("Rob Mehar", p2);
Billing p5 = new Billing(p3, p1, p1.getOfficeFee());
Billing p6 = new Billing(p4, p2, p2.getOfficeFee());
System.out.println("Record 1:");
System.out.println(p5);
System.out.println("Record 2:");
System.out.println(p6);
System.out.println("Total due amount: $" + (p5.getDueAmount() + p6.getDueAmount()));
}
}
Output:
Record 1:
Patient: Peter Mark, Physician: Josh Samuel, Fee: $85.0
Record 2:
Patient: Sam Peter, Physician: Rob Mehar, Fee: $90.0
Total due amount: $175.0