Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create the definition of two classes, Patient and Billing, whose objects are records for a clinic. Patient will be derived from the class Person given

Create the definition of two classes, Patient and Billing, whose objects are records for a clinic. Patient will be derived from the class Person given below.

The skeleton of the definition of the class Person is listed below. Completing the definitions of the methods is part of this programming project.

public class Person {

private String name;

public Person() {...}

public Person(String theName) {...}

public Person(Person theObject) {...}

public String getName() {...}

public void setName(String theName) {...}

public String toString() {...}

public boolean equals(Object other) {...}

}

A Patient record has the patients name (inherited from the class Person) and primary physician of type Doctor defined as follows.

Give the definition of a class named Doctor whose objects are records for a clinics doctors. This class will be a derived class of the class SalariedEmployee given in our class (code is included, make sure you have attached the correct header and include comments in the code). A Doctor record has the doctors specialty (such as "Pediatrician", "Obstetrician", "General Practitioner", and so forth; so use the type String) and office visit fee (use type double). Be sure your class has a reasonable complement of constructors, accessor, and mutator methods, and suitably defined equals and toString methods. Write a program to test all your methods.

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.

Create the classes as described before. Then 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.

SalariedEmployee.java

/** Class Invariant: All objects have a name string, hire date, and nonnegative salary. A name string of "No name" indicates no real name specified yet. A hire date of Jan 1, 1000 indicates no real hire date specified yet. */ public class SalariedEmployee extends Employee { private double salary; //annual

public SalariedEmployee( ) { super( ); salary = 0; }

/** Precondition: Neither theName nor theDate are null; theSalary is nonnegative. */ public SalariedEmployee(String theName, Date theDate, double theSalary) { super(theName, theDate); if (theSalary >= 0) salary = theSalary; else { System.out.println("Fatal Error: Negative salary."); System.exit(0); } }

public SalariedEmployee(SalariedEmployee originalObject ) { super(originalObject); salary = originalObject.salary; }

public double getSalary( ) { return salary; }

/** Returns the pay for the month. */ public double getPay( ) { return salary/12; }

/** Precondition: newSalary is nonnegative. */ public void setSalary(double newSalary) { if (newSalary >= 0) salary = newSalary; else { System.out.println("Fatal Error: Negative salary."); System.exit(0); } }

public String toString( ) { return (getName( ) + " " + getHireDate( ).toString( ) + " $" + salary + " per year"); }

public boolean equals(SalariedEmployee other) { return (getName( ).equals(other.getName( )) && getHireDate( ).equals(other.getHireDate( )) && salary == other.salary); } }

Employee.java

/** Class Invariant: All objects have a name string and hire date. A name string of "No name" indicates no real name specified yet. A hire date of Jan 1, 1000 indicates no real hire date specified yet. */ public class Employee { private String name; private Date hireDate;

public Employee( ) { name = "No name"; hireDate = new Date("Jan", 1, 1000); //Just a placeholder. }

/** Precondition: Neither theName nor theDate is null. */ public Employee(String theName, Date theDate) { if (theName == null || theDate == null) { System.out.println("Fatal Error creating employee."); System.exit(0); } name = theName; hireDate = new Date(theDate); }

public Employee(Employee originalObject) { name = originalObject.name; hireDate = new Date(originalObject.hireDate); }

public String getName( ) { return name; }

public Date getHireDate( ) { return new Date(hireDate); }

/** Precondition newName is not null. */ public void setName(String newName) { if (newName == null) { System.out.println("Fatal Error setting employee name."); System.exit(0); } else name = newName; }

/** Precondition newDate is not null. */ public void setHireDate(Date newDate) { if (newDate == null) { System.out.println("Fatal Error setting employee hire date."); System.exit(0); } else hireDate = new Date(newDate); }

public String toString( ) { return (name + " " + hireDate.toString( )); }

public boolean equals(Employee otherEmployee) { return (name.equals(otherEmployee.name) && hireDate.equals(otherEmployee.hireDate)); } }

JAVA

image text in transcribed

image text in transcribed

Part B (50%) Create the definition of two classes, Patient and Billing, whose objects are records for a clinic. Patient will be derived from the class Person given below. The skeleton of the definition of the class Person is listed below. Completing the definitions of the methods is part of this programming project. public class Person { private String name; public Person() {...} public Person (String theName) {...} public Person (Person theObject) {...) public String getName() {...} public void setName (String theName) {...} public String toString() {...} public boolean equals (Object other) {...} A Patient record has the patient's name inherited from the class Person) and primary physician of type Doctor defined as follows. Give the definition of a class named Doctor whose objects are records for a clinic's doctors. This class will be a derived class of the class SalariedEmployee given in our class (code is included, make sure you have attached the correct header and include comments in the code). A Doctor record has the doctor's specialty (such as "Pediatrician", "Obstetrician", "General Practitioner", and so forth; so use the type String) and office visit fee (use type double). Be sure your class has a reasonable complement of constructors, accessor, and mutator methods, and suitably defined equals and toString methods. Write a program to test all your methods. 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. Create the classes as described before. Then 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

From Zero To Data Hero With Chatgpt

Authors: Andrew Wu

1st Edition

B0CQRJPXD9, 979-8989523009

More Books

Students also viewed these Databases questions