Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a payroll program named CalcPay that allows the user to enter two double

ID: 3606385 • Letter: C

Question

Create a payroll program named CalcPay that allows the user to enter two double valuesand a string namely hours worked, hourly rate and name. After the user enters the rate, hours,and name the program should calculate the gross pay. Compute federal withholding tax which is subtracted from gross based on the following table: Hints: (100pts) Use methods as deemed appropriate. 0 to 99.99 6% 100.00 to 299.99 12% 300.00 to 599.99 18% 600.00 and up 21%. Create an output using printf format: the output should include: Name, hours, rate, deduct, gross and net. In Java.

Explanation / Answer

import java.util.Scanner;

public class payroll {

// method to calculate gross_pay

public static double CalcPay(double hours_worked,double hourly_rate)

{

double result = hours_worked*hourly_rate; // gross pay

return result;

}

//method to calculate federal withholding tax

public static double federalWithholdingTax(double gs_pay)

{

double result = 0;

if(gs_pay < 100){

result = 0.06*gs_pay; // if less than 100 => 6%

}

else if(gs_pay < 300){

result = 0.12*gs_pay; // if less than 300 => 12%

}

else if(gs_pay < 600){

result = 0.18%gs_pay; // if less than 600 => 18%

}

else{

result = 0.21*gs_pay; // more than or equal to 600 => 21%

}

return result;

}

public static void main(String[] args) {

// TODO Auto-generated method stub

// to take input from user

Scanner scan = new Scanner(System.in);

System.out.print("Enter your name: ");

String name = scan.nextLine(); // name of user

System.out.print("Enter the hours worked and hourly rate: ");

double hours_worked = scan.nextDouble();

double hourly_rate = scan.nextDouble();

//gross pay

double gs_pay = CalcPay(hours_worked,hourly_rate);

//federal withholding tax

double fw_tax = federalWithholdingTax(gs_pay);

//net pay

double net = gs_pay - fw_tax;

System.out.println("name = "+name+", hours_worked = "+hours_worked+", rate = "+

hourly_rate+", deduct = "+fw_tax+", gross = "+gs_pay+" and net = "+net);

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote