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

Create a new Java project. Name the class Employee.java. 1. Create four instance

ID: 3729516 • Letter: C

Question

Create a new Java project. Name the class Employee.java.

1. Create four instance variables:

- Employee ID

- Employee name

- Hours Worked

- Pay rate

A. Create the following methods:

- Calculate gross pay

- Calculate net pay using tax rate of 15%

- The display prints ID, name, gross pay, net pay

2. Create an application class named Payroll.

A. Create two new employees

B. Call each of the methods for each employee.

C. The Payroll application does not do any calculation, only the Employee class.

D. Sample Output:

123

Bill

Gross Pay: $370.12

Net pay: $314.61

456

Steve

Gross pay: $612.38

Net pay: $520.52

Employee ID Employee Name Hours Worked Pay Rate 123 Bill 23.5 15.75 456 Steve 35.5 17.25

Explanation / Answer

public class Employee {

  

   private int id;

   private String name;

   private double hours;

   private double payRate;

  

   public Employee(int id, String name, double hours, double payRate) {

       this.id = id;

       this.name = name;

       this.hours = hours;

       this.payRate = payRate;

   }

  

   public double grossPay() {

       return hours*payRate;

   }

   public double netPay() {

       double gp = grossPay();

       return (gp - gp*0.15);

   }

  

   public void print() {

       System.out.println("Id: "+id+", Name: "+name+", gross pay: "+

   grossPay()+", net pay: "+netPay());

   }

}

#############

public class Payroll {

  

   public static void main(String[] args) {

      

       Employee e1 = new Employee(123, "Bill", 23.5, 15.75);

       Employee e2 = new Employee(456, "Steve", 35.5, 17.25);

      

      

      

       e1.print();

       e2.print();

      

   }

}

/*

Sample run:

Id: 123, Name: Bill, gross pay: 370.125, net pay: 314.60625

Id: 456, Name: Steve, gross pay: 612.375, net pay: 520.51875

*/

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