Create a payroll program named CalcPay that allows the user to enter two double
ID: 3606417 • Letter: C
Question
Create a payroll program named CalcPay that allows the user to enter two double values and 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.
Explanation / Answer
CalcPay.java
import java.util.Scanner;
public class CalcPay {
public static void main(String[] args) {
// Declaring variables
double hoursWorked, hourlyRate;
double grosspay, federalTax, netpay;
String name;
/*
* Creating an Scanner class object which is used to get the inputs
* entered by the user
*/
Scanner sc = new Scanner(System.in);
System.out.println(" ____ Displaying the Info ____");
// Getting the input entered by the user
System.out.print("Enter the name :");
name = sc.nextLine();
System.out.print("Enter No of hours worked :");
hoursWorked = sc.nextDouble();
System.out.print("Enter the hourly rate :$");
hourlyRate = sc.nextDouble();
// calculating the grosspay
grosspay = hoursWorked * hourlyRate;
// calling the method by passing the grosspay
federalTax = calcFederalTax(grosspay);
// calculating the netpay
netpay = grosspay - federalTax;
// Displaying the output
System.out.println("Name :" + name);
System.out.printf("No of Hours Worked :%.2f ", hoursWorked);
System.out.printf("Hourly rate :$ %.2f ", hourlyRate);
System.out.printf("Gross Pay :$ %.2f ", grosspay);
System.out.printf("Tax Deductions :$ %.2f ", federalTax);
System.out.printf("Net Pay :$ %.2f ", netpay);
}
private static double calcFederalTax(double grosspay) {
double federalTax = 0.0;
if (grosspay >= 0 && grosspay <= 99.99) {
federalTax = 0.06 * grosspay;
} else if (grosspay >= 100.0 && grosspay <= 299.99) {
federalTax = 0.12 * grosspay;
} else if (grosspay >= 300.0 && grosspay <= 599.99) {
federalTax = 0.18 * grosspay;
} else if (grosspay >= 600.0) {
federalTax = 0.21 * grosspay;
}
return federalTax;
}
}
__________________
Output:
____ Displaying the Info ____
Enter the name :Sachin
Enter No of hours worked :43
Enter the hourly rate :12.5
Name :Sachin
No of Hours Worked :43.00
Hourly rate :$ 12.50
Gross Pay :$ 537.50
Tax Deductions :$ 96.75
Net Pay :$ 440.75
_____________Could you rate me well.Plz .Thank You
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.