//File: Employee3.java import CSLib.*; /** * This class represents Employees * @author Bill Steinmetz */ public class Employee3 { //Attributes (data) of Employee - Instance Variables private String firstName, lastName; private double hoursWorked, payRate, salary; //Overloaded constructors /** * Employee3 default constructor initializes each * instance variable to null (Strings) or 0 (doubles) */ public Employee3 () {} /** * Employee3 constructor * @param f firstName * @param l lastName * @param h hoursWorked * @param p payRate */ public Employee3 (String f, String l, double h, double p) { firstName = f; lastName = l; hoursWorked = h; payRate = p; } //Behavior (operations) of Employee- Instance Methods //Accessor methods /** * @return a String representing all of * the Employee's data */ public String toString() { return firstName + " " + lastName + " worked " + hoursWorked + " hours at $ " + payRate + " per hour and earned $ " + salary + "."; } /** * @return a String representing the Employee's full name */ public String getName() { return firstName + " " + lastName; } //Mutator Methods /** * Calculates the Employee's salary including time worked * beyond 40 hours per week (overtime) */ public void calculateSalary () { if (hoursWorked < 40) { salary = payRate * hoursWorked; } else { salary = payRate * 40 + 1.5 * payRate * (hoursWorked - 40); } } /** * Interactively assigns the Employee's first and last names */ public void setName() { InputBox in = new InputBox(); in.setPrompt ("First name please: "); firstName = in.readString(); in.setPrompt ("Last name please: "); lastName = in.readString(); } /** * Interactively assigns the number of hours worked */ public void setHoursWorked() { InputBox in = new InputBox(); in.setPrompt ("How many hours did you work last week? "); hoursWorked = in.readDouble(); } /** * Interactively assigns the Employee's rate of pay */ public void setPayRate() { InputBox in = new InputBox(); in.setPrompt ("What is your hourly pay rate? "); payRate = in.readDouble(); } }