Gross Pay <= 300.00 = 10%
Gross Pay <= 400.00 = 12%
Gross Pay <= 500.00 = 15%
Gross Pay . 500.01 = 20%
Here is what I have
[import java.util.Scanner; //Needed for scanner class.
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 GrossPay;
private double Tax;
/**
Constructor
@param Name The name to store in EmployeeName.
@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){
return HourlyPayRate * HoursWorked;
}
else{
double regPay =REG_HOURS * HourlyPayRate;
double otPay = (HoursWorked - REG_HOURS) * OT_RATE * HourlyPayRate;
return regPay + otPay;
}
}
public double getTaxWitholding()
{
if (GrossPay <= 300.00)
Tax = .10 * GrossPay;
else if (GrossPay <= 400.00)
Tax = .12 * GrossPay;
else if (GrossPay <= 500.00)
Tax = .15 * GrossPay;
else if (GrossPay > 500.01)
Tax = .20 * GrossPay;
return Tax;
}
}
and my test
import 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;
double TaxWitholding = 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());
System.out.println("The Tax Withholding for " + IDnumber + " is: " + pay.getTaxWitholding());
}
}
*** Edit ***
Please use code tags when posting code
This post has been edited by GunnerInc: 06 December 2012 - 09:27 PM
Reason for edit:: Added elusive code tags

New Topic/Question
Reply



MultiQuote




|