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

Use Java To(with Explaination of Steps Please): You’re given a class Employee th

ID: 3796350 • Letter: U

Question

Use Java To(with Explaination of Steps Please):

You’re given a class Employee that represents a worker in some unknown industry.Each employee has a name , balance and an hourly rate that is unique to them. So Worker1 can have a rate of $5 per hour and Worker2 can have $8 per hour. There are 2 constructors – one that lets you specify the name, a starting balance and the rate,and another that only lets you specify the name and rate and defaults the balance to 0. There are 3 methods for the Employee class – a “ work(int hours) ” method that adds money to that worker's balance, a “ spend (double money) ” method, and a “ printInfo() ” method which prints that workers name, rate, and balance. Now write a new program ( EmployeeDriver ) that creates 3 workers, assigns them to work a few shifts, spend some of their money, then prints out the information for each worker. Make use of all of the constructors and instance variables and methods available in the Employee. (20 marks)

Example run : (not all methods are used in this example)

java Employee creating employees…

Employee name is Bob, rate is 50, balance is 3000

Employee name is Rob, rate is 20 , balance is 1000

Employee name is Tom, rate is 10, balance is 0 working

employees a few hours…

Employee name is Bob, rate is 50, balance is 3500

Employee name is Rob, rate is 20, balance is 1400

Explanation / Answer

Hi, Please find my implementation.

Please let me know in case of any issue.

######### Employee.java #############

public class Employee {

   // instance variables

   private String name;

   private double rate;

   private double balance;

   // constructor

   public Employee(String name, double rate, double balance) {

       this.name = name;

       this.rate = rate;

       this.balance = balance;

   }

   public Employee(String name, double rate) {

       this.name = name;

       this.rate = rate;

       this.balance = 0;

   }

  

   public void work(int hours){

       balance = balance + rate*hours;

   }

  

   public void spend (double money){

       balance = balance - money;

   }

  

   public void printInfo(){

       System.out.println("Employee name is "+name+", rate is "+rate+", balance is "+balance);

   }

}

###################   EmployeeDriver.java ###############

public class EmployeeDriver {

   public static void main(String[] args) {

      

       // creating three Employee Objects

       Employee emp1 = new Employee("Bob", 50, 5000);

       Employee emp2 = new Employee("Rob", 20, 1000);

       Employee emp3 = new Employee("Rob", 10);

       emp1.printInfo();

       emp2.printInfo();

       emp3.printInfo();

       emp1.work(10);

       emp1.printInfo();

       emp2.work(20);

       emp2.printInfo();

       emp3.work(40);

       emp3.printInfo();

      

       emp2.spend(700);

       emp2.printInfo();

   }

}

/*

Sample run:

Employee name is Bob, rate is 50.0, balance is 5000.0

Employee name is Rob, rate is 20.0, balance is 1000.0

Employee name is Rob, rate is 10.0, balance is 0.0

Employee name is Bob, rate is 50.0, balance is 5500.0

Employee name is Rob, rate is 20.0, balance is 1400.0

Employee name is Rob, rate is 10.0, balance is 400.0

Employee name is Rob, rate is 20.0, balance is 700.0

*/

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