Write a class that contains variables that hold your hourly rate of pay and the number of hours that you worked. Display your gross pay, your tax please refer in the table below and your net pay (gross pay – tax).
Gross pay Tax
----------------------------------------
Below 2000 | No tax
2001 - 3000 | 5%
Above 3000 | 10 %
public class Pay {
private int hourlyRateOfPay;
private int numberOfHours;
public Pay(int hourlyRateOfPay, int numberOfHours) {
this.hourlyRateOfPay = hourlyRateOfPay;
this.numberOfHours = numberOfHours;
}
public int getHourlyRateOfPay() {
return hourlyRateOfPay;
}
public void setHourlyRateOfPay(int hourlyRateOfPay) {
this.hourlyRateOfPay = hourlyRateOfPay;
}
public int getNumberOfHours() {
return numberOfHours;
}
public void setNumberOfHours(int numberOfHours) {
this.numberOfHours = numberOfHours;
}
}
public static void main (String[] args) {
Pay pay = new Pay(45, 80);
int grossPay = pay.getHourlyRateOfPay() * pay.getNumberOfHours();
int tax;
if (grossPay <= 2000) {
tax = 0;
} else if (grossPay >= 2001 && grossPay <= 3000){
tax = 5;
} else {
tax = 10;
}
System.out.println("Gross pay: " + grossPay);
System.out.println("Tax: " + tax);
System.out.println("Net pay: " + (grossPay * (100 - tax) * 0.01));
}
Comments
Leave a comment