Answered step by step
Verified Expert Solution
Question
1 Approved Answer
HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee { private String empName; private int empNumber; private double hoursWorked; private double payRate; private static int
HospitalEmployee Inheritance help please.
import java.text.NumberFormat; public class HospitalEmployee { private String empName; private int empNumber; private double hoursWorked; private double payRate; private static int hospitalEmployeeCount = 0; //----------------------------------------------------------------- // Sets up this hospital employee with default information. //----------------------------------------------------------------- public HospitalEmployee() { empName = "Chris Smith"; empNumber = 9999; hoursWorked = 0; payRate =0; hospitalEmployeeCount++; } //overloaded constructor. public HospitalEmployee(String eName, int eNumber, double hours, double pay) { empName = eName; empNumber = eNumber; hoursWorked = hours; payRate = pay; hospitalEmployeeCount++; } //----------------------------------------------------------------- // Sets the name for this employee. //----------------------------------------------------------------- public void setEmpName (String eName) { empName = eName; } //----------------------------------------------------------------- // Sets the employee number for this employee. //----------------------------------------------------------------- public void setEmpNumber (int eNumber) { empNumber = eNumber; } //----------------------------------------------------------------- // Sets the hours worked for this employee. //----------------------------------------------------------------- public void setHoursWorked (double hours) { hoursWorked = hours; } //----------------------------------------------------------------- // Sets the pay rate for this employee. //----------------------------------------------------------------- public void setPayRate (double rate) { payRate = rate; } //----------------------------------------------------------------- // Returns this employee's name. //----------------------------------------------------------------- public String getEmpName() { return empName; } //----------------------------------------------------------------- // Returns this employee's number. //----------------------------------------------------------------- public int getEmpNumber() { return empNumber; } //----------------------------------------------------------------- // Returns hours worked. //----------------------------------------------------------------- public double getHoursWorked() { return hoursWorked; } //----------------------------------------------------------------- // Returns employee payRate //----------------------------------------------------------------- public double getpayRate() { return payRate; } //----------------------------------------------------------------- // Returns this employee's gross pay. //----------------------------------------------------------------- public double calculateGrossPay() { return (hoursWorked * payRate); } //----------------------------------------------------------------- // This adds or subtracts hours from the hoursWorked instance var. //----------------------------------------------------------------- public void changeHoursWorked(double hours) { hoursWorked = hoursWorked + hours; } //----------------------------------------------------------------- // Changes the instance variable payRate by the amount //----------------------------------------------------------------- public void changePayRate(double amount) { payRate = payRate + amount; } //--------------------------------------------------------------- // Calculates a bonus based on a rating // Returns 500 for excellent employees // Returns 300 for satisfactory employees // Returns 0 for all other ratings // // good example to overload. //--------------------------------------------------------------- public double calculateBonus(String rating) { double bonus = 0.0; rating = rating.toLowerCase(); if (rating.equals("excellent") ) { bonus = 500; } else if (rating.equals("satisfactory") ) { bonus = 300; } //everyone else is 0 return bonus; } //overloaded calculateBonus //bonus is calculated as a percent of gross pay //percent = 10% passed in a 10 public double calculateBonus(double percent) { double bonus = calculateGrossPay() * percent / 100.0; return bonus; } //----------------------------------------------------------------- // Returns a description of this employee as a string. //----------------------------------------------------------------- public String toString() { NumberFormat fmt = NumberFormat.getCurrencyInstance(); return ("empName: " + empName + "\t empNumber: " + empNumber + "\thoursWorked: " + hoursWorked + "\tpayRate: " + fmt.format(payRate) ); } //static method that returns number of HospitalEmployee objects created public static int getHospitalEmployeeCount( ) { return hospitalEmployeeCount; } }Please adhere to the Standards for Programming Assignments and the Java Code and Style Guidelines. Submit the following: List of source code with comments to document Test output listed as comments at the end of your program 1. (10 points) Implement a Doctor class based on the UML below. The Doctor class extends/inherits the HospitalEmployee class. Download the HospitalEmployee class. Doctor specialty: String //area of expertise such as Pediatrics, Surgery, Internal Medicine Doctor(eNamestring, eNumber int, hours double, pay double, special String) //must call super class constructor getSpecialty() String set Specialty (special String) void calculate Bonus(shift: String) double /ight shift -10%. evening shift 5%, day shift -0% //Use calculateBonus(percent) method in HospitalEmployee createLogin0 String //create and return a login. first 2 letters of name random number between 0-9+ employee number toString(): String //must call super class toString 2. (10 points) Implement a tester class called Hospital. Specifically, Hospital should do the following in this order: Create/instantiate a HospitalEmployee object called luke hat has the name Luke Skywalker, an employee number of 5432, hours worked of 40 and a payrate of $20.50 Display the status of luke using toString. Calculate and display luke's bonus. He is a satisfactory employee. Create/instantiate a Doctor object called darth with the name Darth Vader, and employee number of 9876, hours worked of 17, a payrate of $150.00. His specialty is Plastic Surgery Display the status of darth using toString Calculate and display darth's bonus using the calculateBonus method from the Doctor class. He works the evening shift Create and display Darth's login Display the number of HospitalEmployee objects created. Hints Order of compilation: HospitalEmployee, Doctor, Hospital All files should be in the same folderpackage. You may change the visibility modifier of the HospitalEmployee instance variables to protected. Example output Welcome to our Hospital Beginning state of luke empName: Luke Skywalker empNumber: 5432 hoursWorked: 40.0 payRate: $20.50 Luke Sky alker is a satisfactory HospitalEmployee $300.00 Bonus Beginning state of darth empNumber: 9876 hours Worked: 17.0 payRate: $150.00 empName Darth Vader specialty: Plastic Surgery Darth Vader is a Doctor and works the evening shift Bonus $127.50 Darth Vader's login is Da Number of HospitalEmployees created Goodbye
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started