Respuesta :
Answer:
public class Payroll {
private String employeeName;
private int employeeId;
private double ratePerHour;
private double totalWorkHours;
public Payroll(String employeeName, int employeeId) {
this.employeeName = employeeName;
this.employeeId = employeeId;
}
public String getemployeeName() {
return employeeName;
}
public voemployeeId setemployeeName(String employeeName) {
this.employeeName = employeeName;
}
public int getemployeeId() {
return employeeId;
}
public voemployeeId setemployeeId(int employeeId) {
this.employeeId = employeeId;
}
public double getratePerHour() {
return ratePerHour;
}
public voemployeeId setratePerHour(double ratePerHour) {
this.ratePerHour = ratePerHour;
}
public double gettotalWorkHours() {
return totalWorkHours;
}
public voemployeeId settotalWorkHours(double totalWorkHours) {
this.totalWorkHours = totalWorkHours;
}
public double getGrossPay() {
return ratePerHour * totalWorkHours;
}
}
import java.util.Scanner;
public class PayrollTest {
public static voemployeeId main(String[] args) {
Scanner in = new Scanner(System.in);
String employeeName;
int employeeId;
System.out.print("Enter employee's Name: ");
employeeName = in.next();
System.out.print("Enter employee's Id: ");
employeeId = in.nextInt();
Payroll payroll = new Payroll(employeeName, employeeId);
System.out.print("Enter employee's hourly rate: ");
payroll.setratePerHour(in.nextDouble());
System.out.print("Enter employee's total hours worked: ");
payroll.settotalWorkHours(in.nextDouble());
System.out.println("Gross pay = " + payroll.getGrossPay());
}
}
Explanation:
- Inside the Payroll class, initialize variables for employee name, ID number, hourly pay rate, and number of hours worked.
- Define the getter and setter methods for the necessary variables inside the Payroll class.
- Inside the main method, create an object of the Payroll class.
- Get all the employee information as an input from user.
- Call the getter function of the class and display the gross pay of employee.