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

Use Method GetPay to Write a java eclipse program that will implement an Employe

ID: 3668840 • Letter: U

Question

Use Method GetPay to

Write a java eclipse program that will implement an Employee class. The class should have three member variables called name, hoursWorked, and hourlyRate.

The class should exhibit “data hiding”.

Write get and set methods for each member variable.

Write a constructor to initialize all member variables.

Write a method called GetPay that returns the pay that the employee should make. An employee’s pay is the hours worked times the hourly rate.

You should declare two instance of the Employee class inside main() and initialize them with different data (use constructor).

Print name and pay for each employee (hint: use printf)

Explanation / Answer

The below program is compiled with 0 errors. Good Luck with your task !!

import java.util.Scanner;

//constructor of employee to initialize first name, last name, hourly rate, and hours worked

public Employee( String firstName, String lastName, Double hourlyRate, Double hoursWorked)
{
this.firstName = firstName;
this.lastName = lastName;
this.hourlyRate = hourleyRate;
this.hoursWorked = hoursWorked;
} // end employee constructor

// set FIRST NAME
public void setFirstName(String firstName) {
this.firstName = firstName; // store the first name
}//end set FIRST NAME

// get FIRST NAME
public String getFirstName() {
return this.firstName;
} // end get FIRST NAME

// set LAST NAME
public void setLastName(String lastName) {
this.lastName = lastName; // store the first name
}//end set LAST NAME

// get LAST NAME
public String getLastName() {
return this.lastName;
} // end get LAST NAME

//set HOURLY RATE
public void setHourlyRate(Double hourlyRate) {
this.hourlyRate = hourlyRate; // store the hourly rate

//while loop if value is not positive
while ( hourlyRate < 0 ) // verifies if hourly rate is a positive number
{
System.out.printf("Enter HOURLY RATE (as a positive number): "); // prompt
hourlyRate = input.nextDouble(); // read value from user
this.setHourlyRate(hourlyRate); // sets the hourly rate
} //end hourly rate while loop
} // end set HOURLY RATE

//get HOURLY RATE
public Double getHourlyRate() {
return this.hourlyRate;
} // end get HOURLY RATE

//set HOURS WORKED
public void setHoursWorked(Double hoursWorked) {
this.hoursWorked = hoursWorked; // store the hourly rate

//while loop if value is not positive
while ( hoursWorked < 0 ) // verifies if hourly rate is a positive number
{
System.out.printf("Enter HOURS WORKED (as a positive number): "); // prompt
hoursWorked = input.nextDouble(); // read value from user
this.setHoursWorked(hoursWorked); // sets the hours worked
} //end hours worked while loop
} // end set HOURS WORKED

//get HOURS WORKED
public Double getHoursWorked() {
return this.hoursWorked;
} // end get HOURS WORKED

//calculate WEEKLY PAY
public Double calcWeeklyPay() {
weeklyPay = hoursWorked * hourlyRate; // stores weekly pay
return weeklyPay;
} // end calculate WEEKLY PAY

//display EMPLOYEE INFO and WEEKLY PAY
public void displayEmployeeInfo() {
System.out.printf(" Employee Name: %s %s Weekly Pay: $%.2f ",
getFirstName(), getLastName(), calcWeeklyPay() );
System.out.printf("------------------------------------------------ "); // prints a dashed line
} // end method displayEmployeeInfo

//display a welcome message to the Program user
public void displayMessage() {
//Display welcome message
System.out.printf( " Welcome to the Payroll Program! " );
} // end method displayMessage


} // end class employee

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote