Define a class Person that holds person\'s name and appropriate constructors, ge
ID: 3709212 • 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
import java.util.Scanner;
class Person {
protected String m_name;
public Person(String name)
{
m_name = name;
}
public String GetName()
{
return m_name;
}
public void SetName(String name)
{
m_name = name;
}
public boolean HasSameName(Person person)
{
return this.m_name.equals(person.GetName());
}
public void Display() {
System.out.printf("%-20s %s ", "Name", m_name);
}
}
class Doctor extends Person {
String m_specialty;
float m_visitFee;
float m_totalIncome;
Doctor(String name, String specialty, float visitFee)
{
super(name);
m_specialty = specialty;
m_visitFee = visitFee;
m_totalIncome = 0;
}
public String GetSpecialty()
{
return m_specialty;
}
public void SetSpecialty(String specialty)
{
m_specialty = specialty;
}
public float GetVisitFee()
{
return m_visitFee;
}
public void SetVisitFee(float visitFee)
{
m_visitFee = visitFee;
}
public void UpdateTotalIncome()
{
m_totalIncome = m_totalIncome + m_visitFee;
}
@Override
public boolean equals(Object obj) {
if (obj == this)
{
return true;
}
if (obj == null || obj.getClass() != this.getClass())
{
return false;
}
Doctor doctor = (Doctor)obj;
return (m_name.equals(doctor.m_name)) && m_specialty.equals(doctor.m_specialty) && m_visitFee == doctor.m_visitFee;
}
public void Display() {
super.Display();
System.out.printf("%-20s %s ", "Specialty", m_specialty);
System.out.printf("%-20s $%.2f ", "Office Visit Fee", m_visitFee);
System.out.printf("%-20s $%.2f ", "Total Income", m_totalIncome);
System.out.println("------------------------------------");
}
}
class Patient extends Person {
double m_personIdentity;
Patient(String name, double personIdentity)
{
super(name);
m_personIdentity = personIdentity;
}
public double GetPersonIdentity()
{
return m_personIdentity;
}
public void SetPersonIdentity(double personIdentity)
{
m_personIdentity = personIdentity;
}
@Override
public boolean equals(Object obj) {
if (obj == this)
{
return true;
}
if (obj == null || obj.getClass() != this.getClass())
{
return false;
}
Patient patient = (Patient)obj;
return (m_name.equals(patient.m_name)) && m_personIdentity == patient.m_personIdentity;
}
}
class Billing {
private Patient m_patient;
private Doctor m_doctor;
Billing(Patient patient, Doctor doctor)
{
m_patient = patient;
m_doctor = doctor;
}
public Patient GetPatient()
{
return m_patient;
}
public Doctor GetDoctor()
{
return m_doctor;
}
}
public class Main {
public static void main(String args[]) {
System.out.println("Enter number of doctor in the facility: ");
Scanner input = new Scanner(System.in);
int numberOFDoctor = input.nextInt();
Doctor[] doctorArrry = new Doctor[numberOFDoctor];
System.out.println("Enter number of patients in the facility: ");
int numberOFPatient = input.nextInt();
Patient[] patientArrry = new Patient[numberOFPatient];
System.out.println("=============================================");
System.out.println("Create Doctor Array");
System.out.println("=============================================");
for (int i = 0; i < numberOFDoctor; i++)
{
Doctor doc;
System.out.println("Doctor " + i);
System.out.println("Enter doctor's name: ");
String docName = input.next();
System.out.println("Enter Specialty: ");
String docSpecialty = input.next();
System.out.println("Enter office visit fee: ");
Float docFee = input.nextFloat();
doc = new Doctor(docName, docSpecialty, docFee);
doctorArrry[i] = doc;
}
System.out.println("=============================================");
System.out.println("Create Patient Array");
System.out.println("=============================================");
for (int i = 0; i < numberOFPatient; i++)
{
Patient patient;
System.out.println("Patient " + i);
System.out.println("Enter Patient's name: ");
String patientName = input.next();
System.out.println("Enter Patient ID: ");
double patientID = input.nextDouble();
patient = new Patient(patientName, patientID);
patientArrry[i] = patient;
}
System.out.println("AppointSetup ");
Billing[] billingArray = new Billing[250];
int billCounter = 0;
while (true)
{
System.out.println("Do you want to setup apppointment (y/n)");
char respond = input.next().charAt(0);
if (respond == 'y' || respond == 'Y')
{
System.out.println("Enter doctor's index");
int doctorIndex = input.nextInt();
if (doctorIndex >= numberOFDoctor)
{
System.out.println("Index is greater than doctors");
continue;
}
System.out.println("Enter patient's index");
int patientIndex = input.nextInt();
if (patientIndex >= numberOFPatient)
{
System.out.println("Index is greater than patient");
continue;
}
doctorArrry[doctorIndex].UpdateTotalIncome();
Billing b = new Billing(patientArrry[patientIndex], doctorArrry[doctorIndex]);
billingArray[billCounter] = b;
billCounter++;
}
else if (respond == 'n' || respond == 'N')
{
break;
}
}
for (int i = 0; i < numberOFDoctor; i++)
{
doctorArrry[i].Display();
}
//check object classes
System.out.println("Do you want check Doctor Object class: (y/n");
char respond = input.next().charAt(0);
if (respond == 'y' || respond == 'Y')
checkObjectClassDoctor(input, doctorArrry[0]);
System.out.println("Do you want check Patient object class: (y/n");
respond = input.next().charAt(0);
if (respond == 'y' || respond == 'Y')
checkObjectClassPatient(input, patientArrry[0]);
input.close();
}
public static void checkObjectClassDoctor(Scanner input, Doctor d) {
System.out.println("Enter Doctor's name: ");
String name = input.next();
System.out.println("Enter Doctor's specialty: ");
String specialty = input.next();
System.out.println("Enter office visit fee: ");
float fee = input.nextFloat();
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.next();
System.out.println("Enter Patients's ID:");
double id = input.nextDouble();
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");
}
}
//PLEASE PROVIDE FEEDBACK THUMBS UP
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.