Question
Create a java class The Payroll Class contains three fields and methods to calculate the wage of an employee. (1) Please write an application that
Create a java class The Payroll Class contains three fields and methods to calculate the wage of an employee.
(1) Please write an application that would allow the user to enter employees name, pay rate, and number of hours he/she worked last week. Use the information to instantiate objects of Payroll class, and add each object into an ArrayList.
(2) The user can enter any number of employees. The program should ask the user whether there is any more data to be entered.
(3) After the user finishes entering the payroll information, print all the payroll information. (NOTE: you can directly use the toString() method of ArrayList.
(4) Use a loop to traverse the ArrayList, get each object, use the calWage() method of Payroll to calculate the total wage the employer needs to pay this week.
The result should be look like this :
The payroll class used to call the methods is the following.
public class Payroll { public final double MINIMUM_RATE = 10.25; // defines the minimum hourly pay rate public final int REGULAR_HOUR = 40; // defines the number of regular hours public final double OVERTIME_RATE = 1.5; // defines the pay rate for overtime hours private String empName; // employee name private double payRate; // payRate for an employee private int numOfHours; // hours worked for an employee // no-arg constructors. It will set the empName to null, payRate and numOfHours to 0. public Payroll(){} public Payroll(String n, double r, int h) { empName = n; // if the rate is less than the minimum pay rate // set it to the minimum pay rate if (r REGULAR_HOUR) return payRate * ((numOfHours-REGULAR_HOUR)* OVERTIME_RATE+ REGULAR_HOUR); // regular pay else return payRate * numOfHours; } public String toString(){ return empName+" worked "+ numOfHours+ " hour(s) at $"+ payRate +" per hour. ";gram Files Java jre1 cterminated> PayrollApD [Java Please enter the name of the employee: Adrian Please enter the pay rate: 9 Please enter the number of hours worked 20 Enter payroll information? (Y/N)Y ation] C: Please enter the name of the employee: Blake Please enter the pay rate: 11 Please enter the number of hours worked:3 Enter payroll information? (Y/N)Y Please enter the name of the employee: Clay Please enter the pay rate: 15 Please enter the number of hours worked: 45 Enter payroll information? (Y/N)Y Please enter the name of the employee: Drew Please enter the pay rate: 10.45 Please enter the number of hours worked: 18 Enter payroll information? (Y/N)in The payroll information ent Adrian worked 20 hour(s) at $10.25 per hour , Blake worked 0 hour(s) at $11.0 per hour , Clay worked 45 hour(s) at $15.0 per hour , Drew worked 18 hour(s) at $10.45 per hour. ered: The total wage to pay is $1105.6
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started