Question
========================= JAVA PROGRAM ========================= import java.util.Date; public class Person { // fields of class private String ID ; private String firstName ; private String lastName
=========================
JAVA PROGRAM
=========================
import java.util.Date;
public class Person { // fields of class private String ID ; private String firstName ; private String lastName ; private String title ; private int YOB ; // constructor public Person(String iD, String firstName, String lastName, String title, int yOB) { ID = iD; this.firstName = firstName; this.lastName = lastName; this.title = title; // validating YOB if (yOB >= 1900 && yOB
//getters and setters public String getID() { return ID; } public void setID(String iD) { ID = iD; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getYOB() { return YOB; } public void setYOB(int yOB) { if(yOB >= 1900 && yOB
//Worker.java public class Worker extends Person{
private double hourlyPayRate; //Constructor public Worker(String iD, String firstName, String lastName, String title, int yOB,double hourlyPayRate) { super(iD, firstName, lastName, title, yOB);//will call to Person's constructor this.hourlyPayRate = hourlyPayRate; }
//getter and setter for hourlyPayRate public double getHourlyPayRate() { return hourlyPayRate; }
public void setHourlyPayRate(double hourlyPayRate) { this.hourlyPayRate = hourlyPayRate; } /** * calculate weekly pay * @param hoursWorked * @return */ public double calculateWeeklyPay(double hoursWorked) { double regularWorkHour; double overtimeHour =0; if(hoursWorked > 40) {//if more than regular hours have been worked regularWorkHour = 40; overtimeHour = hoursWorked - 40; }else { regularWorkHour = hoursWorked; } double regularPay = regularWorkHour*hourlyPayRate;//calculate regular pay double overtimePay = overtimeHour*(hourlyPayRate*1.5);//calculate overtime pay double totalPay = regularPay+overtimePay; return totalPay; } /** * display weekly pay * @param hoursWorked * @return */ public String displayWeeklyPay(double hoursWorked) { double regularWorkHour; double overtimeHour =0; if(hoursWorked > 40) { regularWorkHour = 40; overtimeHour = hoursWorked - 40; }else { regularWorkHour = hoursWorked; } double regularPay = regularWorkHour*hourlyPayRate; double overtimePay = overtimeHour*(hourlyPayRate*1.5); double totalPay = regularPay+overtimePay; String display = ""; display +=" Number of hours of regular pay = "+regularWorkHour; display +=" Total regular pay = "+regularPay; display +=" Number of hours of overtime pay = "+overtimeHour; display +=" Total overtime pay = "+overtimePay; display +=" Total combined pay = "+totalPay; return display; }
}
//SalaryWorker.java public class SalaryWorker extends Worker {
private double annualSalary;//privatefield //constructor public SalaryWorker(String iD, String firstName, String lastName, String title, int yOB, double hourlyPayRate,double annualSalary) { super(iD, firstName, lastName, title, yOB, hourlyPayRate);//call to Worker's constructor this.annualSalary = annualSalary;//ser annualSalary }
//getter and setter for annual salary public double getAnnualSalary() { return annualSalary; }
public void setAnnualSalary(double annualSalary) { this.annualSalary = annualSalary; } /** * overridden calculateWeeklyPay * hoursWorked will not be used here - retaimed for polymorphism * weekly pay will be calculated by dividing annualSalary by 52 */ public double calculateWeeklyPay(double hoursWorked) { double weeklyPay = this.annualSalary/52; return weeklyPay; } /** * overridden display weekly pay * hoursWorked will not be used here - retaimed for polymorphism */ public String displayWeeklyPay(double hoursWorked) { double weeklyPay = calculateWeeklyPay(hoursWorked); String display = ""; display = "Weekly pay = "+weeklyPay+"(It is a fraction of yearly Salary "+annualSalary+")"; return display; }
}
1 Create the Java Main Class ApplicationRunner Create 3 Worker Instances. Pick reasonable hourly rates. Of course, they have IDs, Names, Titles, and YOBs. Create 3 SalaryWorker Instances. Pick reasonable annual rates. Of course, they have IDs, Names, Titles, and YOBS. Add them to an ArrayList Write a loop that simulates 3 Weekly pay periods. Week 1 is a 40 hour week. Week 2 was crunch time and everyone worked 50 hours. Week 3 is back to normal with 40 hours. Generate a display showing the weekly pay for each of the workers for each week. Output should look something like this.... Worker: Mr. Yahya Gilany ID#: 00001 Hours Worked at regular Pay Rate: 40.0 and he's getting: 800.0 Hours Worked at overtime Pay Rate: 0.0 and he's getting: 0.0 Hours Worked at regular Pay Rate: 40.0 and he's getting: 800.0 Hours Worked at overtime Pay Rate: 10.0 and he's getting: 300.0 Hours Worked at regular Pay Rate: 40.0 and he's getting: 800.0 Hours Worked at overtime Pay Rate: 0.0 and he's getting: 0.0 Worker: Mr. Tom Lee ID#: 00002 Hours Worked at regular Pay Rate: 40.0 and he's getting: 1600.0 Hours Worked at overtime Pay Rate: 0.0 and he's getting: 0.0 Hours Worked at regular Pay Rate: 40.0 and he's getting: 1600.6 Hours Worked at overtime Pay Rate: 10.0 and he's getting: 600.0 Hours Worked at regular Pay Rate: 40.0 and he's getting: 1600.0 Hours Worked at overtime Pay Rate: 0.0 and he's getting: 0.0 Worker: Mr. George Smith ID#: 00003 Hours Worked at regular Pay Rate: 40.0 and he's getting: 1200.0 Hours Worked at overtime Pay Rate: 0.0 and he's getting: 0.0 Hours Worked at regular Pay Rate: 40.0 and he's getting: 1200.0 Hours Worked at overtime Pay Rate: 10.0 and he's getting: 450.0 Hours Worked at regular Pay Rate: 40.0 and he's getting: 1200.0 Hours Worked at overtime Pay Rate: 0.0 and he's getting: 0.0Step 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