Question: Define two classes, Patient and Billing, whose objects are records for a clinic. A Patient record has the patient s name ( defined in the

Define two classes, Patient and Billing, whose objects are records for a clinic. 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. Give your classes a reasonable complement of constructors and accessor methods, and an equals method as well. 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 displays the total income from the Billing records. Below is what I have so far but I get an error code in the doctor class about the super display. Could someone fix what I have wrong and run the program to work properly?
class Person {
private String name;
public Person(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public boolean hasSameName(Person other){
return this.name.equals(other.name);
}
}
class Doctor extends Person {
private String specialty;
private double visitFee;
private double income =0.0;
public Doctor(String name, String specialty, double visitFee){
super(name);
this.specialty = specialty;
this.visitFee = visitFee;
}
public String getSpecialty(){
return specialty;
}
public void setSpecialty(String specialty){
this.specialty = specialty;
}
public double getVisitFee(){
return visitFee;
}
public void setVisitFee(double visitFee){
this.visitFee = visitFee;
}
public double getIncome(){
return income;
}
public void addIncome(double amount){
income += amount;
}
public boolean equals(Doctor other){
return super.hasSameName(other) && this.specialty.equals(other.specialty) && this.visitFee == other.visitFee;
}
public void display(){
super.display();
System.out.printf("%-20s %s
", "Specialty", specialty);
System.out.printf("%-20s $%.2f
", "Office Visit Fee", visitFee);
System.out.printf("%-20s $%.2f
", "Total Income", income);
System.out.println("------------------------------------");
}
}
class Patient extends Person {
private int patientID;
public Patient(String name, int patientID){
super(name);
this.patientID = patientID;
}
public int getPatientID(){
return patientID;
}
public void setPatientID(int patientID){
this.patientID = patientID;
}
public boolean equals(Patient other){
return super.hasSameName(other) && this.patientID == other.patientID;
}
}
public class BillingRecordDemo {
public static void main(String[] args){
Scanner input = new Scanner(System.in);
System.out.println("Enter number of doctors in the facility: ");
int numDoctors = input.nextInt();
Doctor[] docArray = new Doctor[numDoctors];
System.out.println("Enter number of patients in the facility: ");
int numPatients = input.nextInt();
Patient[] patArray = new Patient[numPatients];
for (int i =0; i < numDoctors; i++){
System.out.println("-------------------------------");
System.out.println("Doctor "+(i +1));
input.nextLine(); // Consume newline
System.out.println("Enter doctor's name: ");
String doctorName = input.nextLine();
System.out.println("Enter Specialty: ");
String specialty = input.nextLine();
System.out.println("Enter office visit fee: ");
double visitFee = input.nextDouble();
docArray[i]= new Doctor(doctorName, specialty, visitFee);
}
for (int i =0; i < numPatients; i++){
System.out.println("-------------------------------");
System.out.println("Patient "+ i);
input.nextLine(); // Consume newline
System.out.println("Enter Patient's name: ");
String patientName = input.nextLine();
System.out.println("Enter Patient ID: ");
int patientID = input.nextInt();
patArray[i]= new Patient(patientName, patientID);
}
char response;
do {
System.out.println("Enter Patient index: ");
int patientIndex = input.nextInt();
System.out.println("Enter Doctor index: ");
int doctorIndex = input.nextInt();
docArray[doctorIndex].addIncome(docArray[doctorIndex].getVisitFee());
System.out.println("Do you want to set another appointment? (y/n)");
response = input.next().charAt(0);
} while (response =='y'|| response =='Y');
for (Doctor doctor : docArray){
doctor.display();
}
System.out.println("Do you want to check Doctor Object class: (y/n)");
char respond = input.next().charAt(0);
if (respond =='y'|| respond =='Y'){
checkObjectClassDoctor(input, docArray[0]);
}
System.out.println("Do you want to check Patient object class: (y/n)");
respond = input.next().charAt(0);
if (respond =='y'|| respond =='Y'){
checkObjectClassPatient(input, patArray[0]);
}
}
public static void checkObjectClassDoctor(Scanner input, Doctor d){
System.out.println("Enter Doctor's name: ");
String name = input.next();
input.nextLine(); // Consume newline
System.out.println("Enter Doctor's specialty: ");
StSystem.out.println("Enter office visit fee: ");
double fee = input.nextDouble();
Doctor doc = new Doctor(name, specialty, fee);
if (d.hasSameName(doc))
System.out.println("Same name");
else
System.out.println(''Not the same name");
if (d.equals(doc))
System.out.println("Same doctor");
else
System.out.println("Not the same doctor");
}
public static void checkObjectClassPatient(Scanner input, patient p){
System.out.println("Enter Patient's Name: ");
String name = input.next();
input.nextLine();
System.out.println("Enter Patient's ID:");
int id = input.nextInt();
Patient pat = new Patient(name, id);
if (p.hasSameName(pat))
System.out.println("Same name");
else
System.out.println("Not the same name");
if (p.equals(pat))
System.out.println("Same patient");
else
System.out.println("Not the same patient");
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!