Write a class that accepts a user’s hourly rate of pay and the number of hours worked. code example
Example 1: Write a class that accepts a user’s hourly rate of pay and the number of hours worked. Display the user’s gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay – withholding). Save the class as Payroll.cs. As illustrated below.
System.out.println("You worked " + hours + "at $" + rate);
Example 2: Write a class that accepts a user’s hourly rate of pay and the number of hours worked. Display the user’s gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay – withholding). Save the class as Payroll.cs. As illustrated below.
System.out.println("You worked " + hours + "at $ + rate");
Example 3: Write a class that accepts a user’s hourly rate of pay and the number of hours worked. Display the user’s gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay – withholding). Save the class as Payroll.cs. As illustrated below.
double tax = 0.15; double withholdingtax = (grosspay * tax);System.out.println("Withholding tax: $"+ withholdingtax);
Example 4: Write a class that accepts a user’s hourly rate of pay and the number of hours worked. Display the user’s gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay – withholding). Save the class as Payroll.cs. As illustrated below.
import java.util.Scanner;public class Payroll{ public static void main(String[] args) { int hours; int rate; int tax; int grosspay; int netpay; int fedtax; Scanner keyBoard = new Scanner(System.in); System.out.print("Enter hourly pay rate: "); rate = keyBoard.nextInt(); System.out.print("Enter hours worked: "); hours = keyBoard.nextInt(); System.out.println("You worked " + hours + "at $ + rate"); System.out.println("Gross pay: + grosspay"); grosspay = (hours * rate); System.out.println("Withholding tax: $ + withholdingtax"); tax = .15; withholdingtax = (grosspay * tax); System.out.println("Net pay: + netpay"); netpay = (grosspay - withholdingtax); }}