public class EmployeeV3 { // Assume that no constructors are declared.
// Field variables
public static void main(String[] args){
String firstName;
String lastName;
double hourlyRate;
boolean gender; // false means male, true means female
// Instance methods
// Assign values to the field variables of an employee.
void setState(String fName, String lName,
double hRate, boolean genderValue) {
firstName = fName;
lastName = lName;
hourlyRate = hRate;
gender = genderValue;
}
// Determines whether an employee is female.
boolean isFemale() { return gender; }
// Computes the salary of an employee, based on the number of hours
// worked during the week.
double computeSalary(double numOfHours) {
assert numOfHours >= 0 : "Number of hours must be >= 0";
double normalNumOfHours = 37.5;
double weeklySalary = hourlyRate * normalNumOfHours;
if (numOfHours > normalNumOfHours) {
weeklySalary += 2.0 * hourlyRate * (numOfHours - normalNumOfHours);
}
return weeklySalary;
}
// Prints the values in the field variables of an employee.
void printState() {
System.out.print("First name: " + firstName);
System.out.print("\tLast name: " + lastName);
System.out.printf("\tHourly rate: %.2f", hourlyRate);
if (isFemale()) {
System.out.println("\tGender: Female"
;
} else {
System.out.println("\tGender: Male"
;
}
}
}
}