Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Define a class Person that holds person\'s name and appropriate constructors, ge

ID: 3708273 • Letter: D

Question

Define a class Person that holds person's name and appropriate constructors, get/set methods, display and hasSameName methods. hasSameName method will return true if two objects of data type Person have the same name.
Then define a class named Doctor whose objects are records for a clinic's doctors. Drive this class from the class Person. A Doctor record has doctor's name, a specialty, and office visit fee. Give your class a reasonable complement of constructors and get/set methods, and an equals method as well. The equals method returns true if two doctor records are the same. Name this class BillingRecordDemo.
Drive Patient form the class Person. A patient record has the Patient's name, and an identification number.
A Billing object will contain a Patient object and a Doctor object. Give your class a reasonable complement of constructors, get/set methods, display and an equals method.
Sample run:

Note: In Doctor class use the following display method:




Use the following template for your Main application Java class.

Explanation / Answer

package clinic;

public class Person {

   // instance variable
   private String name;
   // Parameterized Constructor
   public Person(String name) {
       this.name = name;
   }
   public String getName() {
       return name;
   }
   public void setName(String name) {
       this.name = name;
   }
  
   public boolean hasSameName(Person p)
   {
       return this.getName().equalsIgnoreCase(p.getName());
   }
   @Override
   public String toString() {
       return "Name=" + name;
   }
   public void display() {
       System.out.println("Name=" + name);
      
   }

}

package clinic;

public class Doctor extends Person{
private String specialty;
private double visitFee;

private double income;

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;
}

@Override
   public boolean equals(Object obj) {
      
       return this.equals(obj);
   }

   public void visit(Patient p) {
       income += visitFee;
   }

@Override
public String toString() {
   return "Doctor [" +super.toString()+" , specialty=" + specialty + ", visitFee=" + 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("------------------------------------");
}

}

package clinic;

public class Patient extends Person{

   private int patientId;

   public Patient(String name, int id) {
       super(name);
       this.patientId = id;
   }

   public int getPatientId() {
       return patientId;
   }

   public void setPatientId(int patientId) {
       this.patientId = patientId;
   }

   @Override
   public String toString() {
       return "Patient [patientId=" + patientId + "]" +super.toString();
   }

  
  
}

package clinic;

public class Billing {
   Patient patient;
   Doctor doctor;
  
  
   public Billing() {
       patient=new Patient("", 0);
       doctor=new Doctor("", "", 0);
   }


   public Billing(Patient patient, Doctor doctor) {
       super();
       this.patient = patient;
       this.doctor = doctor;
   }


   public Patient getPatient() {
       return patient;
   }


   public void setPatient(Patient patient) {
       this.patient = patient;
   }


   public Doctor getDoctor() {
       return doctor;
   }


   public void setDoctor(Doctor doctor) {
       this.doctor = doctor;
   }
  
}

package clinic;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

   public static void main(String[] args) {
       // complete this part
       Scanner input = new Scanner(System.in);
       System.out.println("Enter number of doctors in the facility: ");
       int numberOfDoctors = input.nextInt();
       // Create Doctor Array
       Doctor[] docArray = new Doctor[numberOfDoctors];
       System.out.println("Enter number of patients in the facility: ");
       int numberOfPatient = input.nextInt();

       Patient[] patArray = new Patient[numberOfPatient];

       System.out.println("-----------------------------");
       System.out.println("Create Doctor Array: ");
       System.out.println("-----------------------------");
       for (int i = 0; i < numberOfDoctors; i++) {
           System.out.println("Doctor " + (i + 1));
           System.out.println("Enter doctor's name: ");
           input.nextLine();
           String name = input.nextLine();
           System.out.println("Enter Specialty: ");
           String speciality = input.nextLine();
           System.out.println("Enter office visit fee: ");
           double fee = input.nextDouble();
           docArray[i] = new Doctor(name, speciality, fee);
       }

       System.out.println("-----------------------------");
       System.out.println("Create Patient Array: ");
       System.out.println("-----------------------------");
       for (int i = 0; i < numberOfPatient; i++) {
           System.out.println("Patient " + i);
           System.out.println("Enter Patient's name: : ");
           input.nextLine();
           String name = input.nextLine();
           System.out.println("Enter Patient ID: ");
           int id = input.nextInt();

           patArray[i] = new Patient(name, id);
       }

       // create a arraylist of Billing objects
       ArrayList<Billing> billing = new ArrayList<>();
       String choice = "y";
       do {
           System.out.println("Enter Patient index: ");
           int pIndex = input.nextInt();
           System.out.println("Enter Doctor index: ");
           int dIndex = input.nextInt();
           billing.add(new Billing(patArray[pIndex], docArray[dIndex]));
           // Visit
           docArray[dIndex].visit(patArray[pIndex]);
           input.nextLine();
           System.out.println("Do you want to set another appointment? (y/n");
           choice = input.nextLine();
       } while (choice.equalsIgnoreCase("y"));

       // Print Doctor Details
       for (Billing billing2 : billing) {
           billing2.getDoctor().display();
       }

      
       // check object classes
       System.out.println("Do you want check Doctor Object class: (y/n");
       char respond = input.nextLine().charAt(0);
       if (respond == 'y' || respond == 'Y')
           checkObjectClassDoctor(input, docArray[0]);

       System.out.println("Do you want check Patient object class: (y/n");
       respond = input.nextLine().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.nextLine();
       System.out.println("Enter Doctor's specialty: ");
       String specialty = input.nextLine();
       System.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 have 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.nextLine();
       System.out.println("Enter Patients'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 have same name");

       if (p.equals(pat))
           System.out.println("Same patient");
       else
           System.out.println("Not the same patient");
   }

}

Output

Enter number of doctors in the facility:
2
Enter number of patients in the facility:
3
-----------------------------
Create Doctor Array:
-----------------------------
Doctor 1
Enter doctor's name:
wwwww
Enter Specialty:
wwww
Enter office visit fee:
50
Doctor 2
Enter doctor's name:
axasxxs
Enter Specialty:
ssss
Enter office visit fee:
100
-----------------------------
Create Patient Array:
-----------------------------
Patient 0
Enter Patient's name: :
dwdwdw
Enter Patient ID:
1
Patient 1
Enter Patient's name: :
wdwdedqwdw
Enter Patient ID:
2
Patient 2
Enter Patient's name: :
wwdwqdwwfefefe
Enter Patient ID:
3
Enter Patient index:
0
Enter Doctor index:
0
Do you want to set another appointment? (y/n
n
Name=wwwww
Specialty            wwww
Office Visit Fee     $50.00
Total Income         $50.00
------------------------------------
Do you want check Doctor Object class: (y/n
n
Do you want check Patient object class: (y/n
n

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote