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

Java hospital employee and hospital classes. Implement a class called HospitalEm

ID: 3805720 • Letter: J

Question

Java hospital employee and hospital classes.

Implement a class called HospitalEmployee that represents an employee in a hospital based on the following informal UML diagram. Adhere to the UML diagram. Do not add additional instance variables or methods. private String empName private int empNumber private double hoursWorked private double payRate public Hospital Employee ()//default constructor. Assigns instance variables a default value.//e,ployee to your name, empNumber to 9999, hoursWorked to 0, payRate to 0 public String getEmpName() public//returns the employee's name int getEmpNumber() public double//returns the employee's n getHours Worked() public double//returns the hours an employee worked getPay Rate()//returns the employee's pay rate public void setEmpName (String ename)//sets the name for this employee public void setEmpNumber(int enumber)//sets the employee number for this employee public void setHoursWorked(double hours)//sets the hours worked for this employee public void setPayRate(double rate)//sets the pay rate for this employee public double calculateGrossPay()//calculates and returns the employee's gross pay (hours worked * pay rate) public void changeHoursworked (double hours)//changes the instance variable hoursWarked by the hours//hours Worked should be updated to hoursWorked + hours The output from running Hospital should be as follows: (of course, your output will use your actual name) public void changePayRate(double amount)//changes the instance variable payRate by the amount Welcome to our Hospital//payRate should be updated to payRate + amount public double calculateBonus(String rating)//returns 500 if rating is "excellent"//returns 300 if rating is "satisfactory"//All other ratings return 0 public String to String()//returns the current state of this as a String//current values of all instance variables is called the current state) Implement a tester class called Hospital. java to test (or use) methods in the HospitalEmployee class. This file is also called a controller or driver program. Hospital should do the following in this order.//create a HospitalEmployee called worker1//display the state of object worker1 using the toString method//set the pay rate of worker1 to 20.00 u the setPayRate method//display the state of objec worker1 using the toString method//change/increase the pay rate of worker1 by 4.50 using the changePayRate method//change/increase the hours worked off worker1 by 30 using the changeHoursWorked method//display the state of worker1 using the toString method//display the name and gross pay of worker1 using getEmpName and calculateGrossPay methods.//calculate a bonus for worker1 using the calculateBonus method. worker1 is an excellent employee.//display the name, bonus, and total earnings of worker1.

Explanation / Answer

HospitalEmployee.java

import java.text.NumberFormat;

public class HospitalEmployee {
   //Declaring instance variables
   private String empName;
   private int empNumber;
   private double hoursWorked;
   private double payrate;
  
   //Zero argumented constructor
   public HospitalEmployee() {
       this.empName="Your Name";
       this.empNumber=9999;
       this.hoursWorked=0.0;
       this.payrate=0.0;

   }
  
   //Setters and getters
   public String getEmpName() {
       return empName;
   }

   public void setEmpName(String empName) {
       this.empName = empName;
   }

   public int getEmpNumber() {
       return empNumber;
   }

   public void setEmpNumber(int empNumber) {
       this.empNumber = empNumber;
   }

   public double getHoursWorked() {
       return hoursWorked;
   }

   public void setHoursWorked(double hoursWorked) {
       this.hoursWorked = hoursWorked;
   }

   public double getPayrate() {
       return payrate;
   }

   public void setPayrate(double payrate) {
       this.payrate = payrate;
   }
  
   //This method will calculate the gross pay
public double calculateGrossPay()
{
   return hoursWorked*payrate;
}

//this method will add the hours the existing hours value
public void changeHoursWorked(double hours)
{
   this.hoursWorked=this.hoursWorked+hours;
}
//this method will add the payrate the existing payrate
public void changePayRate(double amount)
{
   this.payrate=this.payrate+amount;
}

//This method will calculate the bonus
public double calculateBonus(String rating)
{
   if(rating.equals("excellent"))
       return 500;
   else if(rating.equals("satisfactory"))
       return 300;
   else
       return 0;
}

//toString method is used to display the contents of an object inside it
@Override
public String toString() {
   NumberFormat fmt = NumberFormat.getCurrencyInstance();
   return "Employee : " + empName + " empNumber=" + empNumber
           + " hoursWorked=" + hoursWorked + " payrate=" +fmt.format(payrate);
}

}

____________________

Hospital.java

import java.text.NumberFormat;

public class Hospital {

   public static void main(String[] args) {
       //Creating an object for the Number format class to format the currency
       NumberFormat fmt = NumberFormat.getCurrencyInstance();
      
       //creating an instance for the HospitalEmployee class
       HospitalEmployee worker1=new HospitalEmployee();
      
       //Displaying the content inside it
       System.out.println(worker1.toString());
      
       //Setting the payrate
       worker1.setPayrate(20.00);
      
       //Displaying the content inside it
       System.out.println(worker1.toString());
      
       //changing the payrate
       worker1.changePayRate(4.50);
      
       //changing the hours worked
       worker1.changeHoursWorked(30);
      
       //Displaying the content inside it
       System.out.println(worker1.toString());
       System.out.print("Employee "+worker1.getEmpName()+" earned "+fmt.format(worker1.calculateGrossPay()));
       double bonus=worker1.calculateBonus("excellent");
       System.out.println(" After Bonus:"+worker1.getEmpName()+" received a bonus of $"+bonus+" and earned a total of "+fmt.format((worker1.calculateGrossPay()+bonus)));
      
      
      

   }

}

_________________

Output:

Employee : Your Name empNumber=9999 hoursWorked=0.0 payrate=$0.00
Employee : Your Name empNumber=9999 hoursWorked=0.0 payrate=$20.00
Employee : Your Name empNumber=9999 hoursWorked=30.0 payrate=$24.50
Employee Your Name earned $735.00
After Bonus:Your Name received a bonus of $500.0 and earned a total of $1,235.00

___________Thank You

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