hi
I have to set an instance variable but just don't know where.Attached is my class with Methods and my Test Class . Any help would be great.
Methods:
public class Payroll { //constants private static final double REG_HOURS = 40; private static final double OT_RATE = 1.5; //Variables private int IDnumber; private double HourlyPayRate; private double HoursWorked; private double TaxWitholding; private double GrossPay; private double grossPay; /** Constructor @param ID The ID to store in Employee ID number. */ public Payroll( int ID) { IDnumber = ID; } 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() { if (HoursWorked <=REG_HOURS){ double grossPay =HourlyPayRate * HoursWorked; return grossPay; } else{ double regPay =REG_HOURS * HourlyPayRate; double otPay = (HoursWorked - REG_HOURS) * OT_RATE * HourlyPayRate; double grossPay = (regPay + otPay); return grossPay; } } public void setgrossPay(double grossPay) { GrossPay =grossPay; } public double getTaxWitholding() { if (GrossPay <= 300.00){ TaxWitholding = .10 * GrossPay; } else if (GrossPay <= 400.00){ TaxWitholding = .12 * GrossPay;} else if (GrossPay <= 500.00){ TaxWitholding = .15 * GrossPay;} else if (GrossPay > 500.01){ TaxWitholding = .20 * GrossPay;} return TaxWitholding; } }
Test Class
Any help would be greatimport java.util.Scanner; //Needed for Scanner class. public class PayrollTest { public static void main(String[] args) { int IDnumber = 0; double HoursWorked=0; double HourlyPayRate=0; double GrossPay = 0; //Create a Scanner object for keyboard input. Scanner in = new Scanner(System.in); //Create a payroll object, IDnumber // as arguments to the constructor. Payroll pay = new Payroll(IDnumber); //Get the employee's ID. System.out.println("Enter the employee's ID " ); IDnumber = in.nextInt(); //Get the number of hours worked by the employee. System.out.println("Enter the number of hours worked: "); HoursWorked= in.nextDouble(); pay.setHoursWorked(HoursWorked); while(pay.getHoursWorked()<=0) { System.out.print("Please enter a number >0. Try Again."); pay.setHoursWorked(in.nextDouble()); } //Get the hourly pay rate of the employee. System.out.println("Enter the hourly pay rate for this employee: "); HourlyPayRate = in.nextDouble(); pay.setHourlyPayRate(HourlyPayRate); while(pay.getHourlyPayRate()<=0) { System.out.print("Please enter a number >0. Try Again."); pay.setHourlyPayRate(in.nextDouble()); } //Get the Gross Pay of the employee. System.out.println("The gross pay for " + IDnumber + " is: " + pay.getGrossPay()); //Get the Gross Pay of the employee. System.out.println("The gross pay for " + IDnumber + " is: "); pay.setgrossPay(GrossPay); pay.getTaxWitholding(); } }