In: Computer Science
Explanation:I have written the classes Pay and PayDemo class which also has the main method to showsthe output of the program, please find the images attached with the answer.I have checked input validation using scanner please comment if you need any other kind of validaton.Please upvote if you liked my answer and comment if you need any modification or explanation.
//Pay class
public class Pay {
private String employeeName;
private int idNumber;
private float hourlyPay;
private float hoursWorked;
public Pay(String employeeName, int idNumber, float
hourlyPay,
float
hoursWorked) {
super();
this.employeeName =
employeeName;
this.idNumber = idNumber;
this.hourlyPay = hourlyPay;
this.hoursWorked =
hoursWorked;
}
public String getEmployeeName() {
return employeeName;
}
public void setEmployeeName(String employeeName)
{
this.employeeName =
employeeName;
}
public int getIdNumber() {
return idNumber;
}
public void setIdNumber(int idNumber) {
this.idNumber = idNumber;
}
public float getHourlyPay() {
return hourlyPay;
}
public void setHourlyPay(float hourlyPay) {
this.hourlyPay = hourlyPay;
}
public float getHoursWorked() {
return hoursWorked;
}
public void setHoursWorked(float hoursWorked) {
this.hoursWorked =
hoursWorked;
}
public float employeeGrossPay() {
return hourlyPay *
hoursWorked;
}
@Override
public String toString() {
return "employeeName=" +
employeeName + ", idNumber=" + idNumber
+ ", hourlyPay=" + hourlyPay + ", hoursWorked="
+ hoursWorked;
}
}
//PayDemo class
import java.util.Scanner;
public class PayDemo {
public static void main(String[] args) {
Scanner input = new
Scanner(System.in);
String employeeName = "";
int idNumber = -1;
float hourlyPay = 0;
float hoursWorked = 0;
System.out.print("Enter name of the
employee:");
if (input.hasNext())
employeeName =
input.nextLine();
else
System.out.println("Invalid input for employee name");
System.out.print("Enter ID number
of the employee:");
if (input.hasNextInt())
idNumber =
input.nextInt();
else
System.out.println("Invalid input for id number");
System.out.print("Enter hourly pay
of the employee:");
if (input.hasNextFloat())
hourlyPay =
input.nextFloat();
else
System.out.println("Invalid input for hourly Pay");
System.out.print("Enter the number
of hours worked of employee:");
if (input.hasNextFloat())
hoursWorked =
input.nextFloat();
else
System.out.println("Invalid input for hours Worked");
Pay employeePay = new
Pay(employeeName, idNumber, hourlyPay,
hoursWorked);
System.out.println(employeePay.toString());
System.out.println("Gross pay: " +
employeePay.employeeGrossPay());
input.close();
}
}
Output: