Answer to Question #311435 in Java | JSP | JSF for aqilah

Question #311435

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 %




1
Expert's answer
2022-03-14T13:04:57-0400
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));
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS