Hi, for some reason I'm getting a value of 0 as my output.
import java.util.Scanner; //Needed for scanner class. public class Payroll{ private String EmployeeName; private int IDnumber; private double HourlyPayRate; private double HoursWorked; private double GrossPay; /** Constructor @param Name The name to store in EmployeeName. @param ID The ID to store in Employee ID number. */ public Payroll(String Name, int ID) { EmployeeName = Name; IDnumber = ID; } public String getEmployeeName() { return EmployeeName; } public int getIDnumber() { return IDnumber; } public void setHourlyPayRate(double HourlyRate) { HourlyPayRate = HourlyRate; } public double getHourlyPayRate() { return HourlyPayRate; } public void setHoursWorked(double hoursWorked) { HoursWorked = hoursWorked; } public double getHoursWorked() { return HoursWorked; } public double getGrossPay() { return HourlyPayRate * HoursWorked; } }
import java.util.Scanner; //Needed for Scanner class. public class PayRollTest { public static void main(String[] args){ { String EmployeeName; int IDnumber; double HoursWorked; double HourlyPayRate; double GrossPay; //Create a Scanner object for keyboard input. Scanner keyboard = new Scanner(System.in); //Get the employee's name. System.out.println("Enter an employee's name: "); EmployeeName = keyboard.nextLine(); //Get the employee's ID. System.out.println("Enter the employee's ID " ); IDnumber = keyboard.nextInt(); //Get the number of hours worked by the employee. //Get the hourly pay rate of the employee. System.out.println("Enter the hourly pay rate for this employee: "); HourlyPayRate = keyboard.nextDouble(); System.out.println("Enter the number of hours worked: "); HoursWorked=keyboard.nextDouble(); //Create a payroll object, passing EmployeeName and IDnumber // as arguments to the constructor. Payroll pay = new Payroll(EmployeeName, IDnumber); pay.setHourlyPayRate(HourlyPayRate); //Get the Gross Pay of the employee. System.out.println("The gross pay of " + EmployeeName + " is: $" + pay.getGrossPay()); } } }