Question

HospitalEmployee Inheritance help please.

ch 8 Inheritance 1. 10 points) Implement a Doctor class based on the UML below. The Doctor class extends/inherits the Hospital Employee class. Download the HospitalEmployee class. Doctor specialty String //area of expertise such as Pediatrics, Surgery, Internal Medicine Doctor(eName: String, eNumber int, hours double, pay double, special String) must call super class constructor getSpecialty(): String setSpecialty (special String):void calculateBonus(shift: String) double llnight shift 10%. evening shift -5%. day shift o% //Use calculateBonus(percent) method in HospitalEmployee createLogin0 String //create and return a login. first 2 letters of name +random number between 0-9 ployee 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: Createl instantiate a HospitalEmployee object called luke that 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 lukes 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 darths bonus using the calculateBonus method from the Doctor class. He works the evening shift. Create and display Darths 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 luke Beginning state of empName: Luke Skywalker empNumber: 5432 ed: 40.0 pay $20.50 e Skywalker is a satisfactory HospitalEmployee. B $300.00 Beginning state of darth empName: Darth Vader mpNumbe Darth Vader is a Doctor and works the evening shift 9876 hours Worked: 17.0 payRate: $150.00 specialty: Plastic surgery Bonus 127.50 Darth Vaders login is Da39876 Number of Ho created Goodbye

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;

  

   }

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.Random;

public class Doctor extends HospitalEmployee{
  
   private String special;
  
   public Doctor(String eName, int eNumber, double hours, double pay, String Special){
       super(eName,eNumber,hours,pay);
       this.special = Special;
   }

   public String getSpecial() {
       return special;
   }

   public void setSpecial(String special) {
       this.special = special;
   }
  
   public double calculateBonus(String shift){
       double bonus = 0.0;
   shift = shift.toLowerCase();
     
   if (shift.equals("night shift") )
   {
   bonus = super.calculateBonus(10);
   } else if (shift.equals("evening shift") )
   {
   bonus = super.calculateBonus(5);
   }
  
   return bonus;
   }
  
   public String createLogin(){
       Random r = new Random();
       int n = r.nextInt(9);
      
       String s = this.getEmpName().substring(0, 1)+ Integer.toString(n)+Integer.toString(this.getEmpNumber());
       return s;
      
   }
  
   public String toString(){
       return super.toString();
   }

}


public class Hospital {

   public static void main(String[] args) {
       // TODO Auto-generated method stub
      
       HospitalEmployee luke = new HospitalEmployee("Luke Skywalker", 5432, 40, 20.50);
       System.out.println("Status of luke: "+luke.toString());
       System.out.println("Bonus of Luke: $"+luke.calculateBonus("satisfactory"));
      
       Doctor darth = new Doctor("Darth Vader", 9876, 17, 150.00, "Plastic Surgery");
      
       System.out.println("Status of Darth: "+darth.toString());
       System.out.println("Bonus of Darth: $"+darth.calculateBonus("evening shift"));
       System.out.println("Login of darth: "+darth.createLogin());
       System.out.println("Number of employees: "+HospitalEmployee.getHospitalEmployeeCount());

   }

}

sterminated Hospital [Java Application] C:Program Files Javaljre1.8.0 131bin javaw.exe (Apr 24, 2017, 11:09:52 AM) Status of

Add a comment
Know the answer?
Add Answer to:
HospitalEmployee Inheritance help please. import java.text.NumberFormat; public class HospitalEmployee {    private String empName;    private...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE =...

    departmentstore: package departmentstorepkg; import java.util.ArrayList; public class DepartmentStore {    private static final int DEFAULT_SIZE = 10; private StaffMember [] myEmployees; private int myNumberEmployees; private String myFileName; private StaffMember[] employee; public DepartmentStore (String filename){ myFileName = filename; myEmployees = employee;    } public String toString(){ return this.getClass().toString() + ": " + myFileName; } public void addEmployee(Employee emp){ } /** * prints out all the employees in the array list held in this class */ public void print(){ for(int i =...

  • Previous class code: 1) Employee.java ------------------------------------------------------------------------------- /** * */ package main.webapp; /** * @author sargade *...

    Previous class code: 1) Employee.java ------------------------------------------------------------------------------- /** * */ package main.webapp; /** * @author sargade * */ public class Employee { private int empId; private String empName; private Vehicle vehicle; public Double calculatePay() { return null; } /** * @return the empId */ public int getEmpId() { return empId; } /** * @param empId * the empId to set */ public void setEmpId(int empId) { this.empId = empId; } /** * @return the empName */ public String getEmpName() { return...

  • Public class Person t publie alass EmployeeRecord ( private String firstName private String last ...

    public class Person t publie alass EmployeeRecord ( private String firstName private String last Nanei private Person employee private int employeeID publie EnmployeeRecord (Person e, int ID) publie Person (String EName, String 1Name) thia.employee e employeeID ID setName (EName, 1Name) : publie void setName (String Name, String 1Name) publie void setInfo (Person e, int ID) this.firstName- fName this.lastName 1Name this.employee e employeeID ID: publio String getFiritName) return firstName public Person getEmployee) t return employeei public String getLastName public int getIDO...

  • By editing the code below to include composition, enums, toString; must do the following: Prompt the...

    By editing the code below to include composition, enums, toString; must do the following: Prompt the user to enter their birth date and hire date (see Fig. 8.7, 8.8 and 8.9 examples) in addition to the previous user input Create a new class that validates the dates that are input (can copy date class from the book) Incorporate composition into your class with these dates Use enums to identify the employee status as fulltime (40 or more hours worked for...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...

    C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below: Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) // Specification file for the ProductionWorker Class #ifndef PRODUCTION_WORKER_H #define PRODUCTION_WORKER_H #include "Employee.h" #include <string> using namespace std; class ProductionWorker...

  • Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so...

    Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...

  • 4. Command pattern //class Stock public class Stock { private String name; private double price; public...

    4. Command pattern //class Stock public class Stock { private String name; private double price; public Product(String name, double price) { this.name = name; this.price = price; } public void buy(int quantity){ System.out.println(“BOUGHT: “ + quantity + “x “ + this); } public void sell(int quantity){ System.out.println(“SOLD: “ + quantity + “x “ + this); } public String toString() { return “Product [name=” + name + “, price=” + price + “]”; } } a. Create two command classes that...

  • import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {   ...

    import java.util.Scanner; public class StudentClient {       public static void main(String[] args)    {        Student s1 = new Student();         Student s2 = new Student("Smith", "123-45-6789", 3.2);         Student s3 = new Student("Jones", "987-65-4321", 3.7);         System.out.println("The name of student #1 is ");         System.out.println("The social security number of student #1 is " + s1.toString());         System.out.println("Student #2 is " + s2);         System.out.println("the name of student #3 is " + s3.getName());         System.out.println("The social security number...

  • I was wondering if I could get some help with a Java Program that I am...

    I was wondering if I could get some help with a Java Program that I am currently working on for homework. When I run the program in Eclipse nothing shows up in the console can you help me out and tell me if I am missing something in my code or what's going on? My Code: public class Payroll { public static void main(String[] args) { } // TODO Auto-generated method stub private int[] employeeId = { 5658845, 4520125, 7895122,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT