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

Problem) 1) Design a PayRoll class that has data members for an employee’s hourl

ID: 3730740 • Letter: P

Question

Problem)

1) Design a PayRoll class that has data members for an employee’s hourly pay rate and number of hours worked.

2) Write a program with an array of eleven PayRoll objects.

3) The program should read the number of hours each employee worked and their hourly pay rate (before tax) from a file and call class function to store this information in the appropriate objects.

4) It should then call class function, once for each object, to return the employee’s net pay after 20% tax deduction, so this information can be displayed.

Explanation / Answer

import java.util.Scanner;

public class PayRoll {

  

   double hours;

   double rate;

  

   public PayRoll(double h, double r) {

       hours = h;

       rate = r;

   }

  

   public static void main(String[] args) {

      

       Scanner sc = new Scanner(System.in);

      

       // creating object

       PayRoll[] arr = new PayRoll[11];

      

       System.out.println("Enter the details of 11 employee: ");

      

       for(int i=0; i<11; i++) {

           System.out.print("Enter hours worked for employee "+(i+1)+": ");

           double h = sc.nextDouble();

          

           System.out.print("Enter pay rate for employee "+(i+1)+": ");

           double r = sc.nextDouble();

          

           arr[i] = new PayRoll(h, r);

       }

      

       // displaying pay

      

       for(int i=0; i<11; i++) {

          

           double pay = arr[i].hours*arr[i].rate;

           pay = pay - pay*0.2;

          

           System.out.println("Pay of employee "+(i+1)+": "+pay);

       }

   }

  

  

}

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