I need help with the tax part A code for the program would b
I need help with the tax part. A code for the program would be good, thanks.
Write ajava program (called payroll.java) that reads worker\'s payroll information and computes the amount of pay for a worker. The worker\'s payroll information to read (using proper prompts) includes: Employee\'s name Number of hours worked Hourly rate of pay Federal tax rate The program then computes and displays the following outputs with appropriate labels. Use the tab escape character or \" \" to align your outputs after the labels. The gross pay is the hours worked times the hourly rate, and the net pay is the gross pay minus all taxes. Employee name Hours worked Hourly rate Gross pay Tax deducted Net paySolution
Hi, Please find my code:
import java.util.Scanner;
public class payroll {
public static void main(String[] args) {
// creating scanner object to take user input
Scanner sc = new Scanner(System.in);
// declaring variables
String employeeName;
int hoursWorked;
double hoursRate;
double taxRate;
// taking usir input
System.out.print(\"Enter name: \");
employeeName = sc.nextLine();
System.out.print(\"Enter number of hours worked: \");
hoursWorked = sc.nextInt();
System.out.print(\"Enter hourly rate: \");
hoursRate = sc.nextDouble();
System.out.print(\"Enter fedral tax rate(%): \");
taxRate = sc.nextDouble();
double grossPay = hoursRate*hoursWorked;
double tax = grossPay*taxRate/100;
double netPay = grossPay-tax;
// output
System.out.println(\"Employee name: \"+employeeName);
System.out.println(\"Hours worked: \"+hoursWorked);
System.out.println(\"Hourly rate: \"+hoursRate);
System.out.println(\"Gross pay: \"+grossPay);
System.out.println(\"Tax deducted: \"+tax);
System.out.println(\"Net pay: \"+netPay);
}
}
/*
Sample Output:
Enter name: Pravesh Kumar
Enter number of hours worked: 40
Enter hourly rate: 3000
Enter fedral tax rate(%): 20
Employee name: Pravesh Kumar
Hours worked: 40
Hourly rate: 3000.0
Gross pay: 120000.0
Tax deducted: 24000.0
Net pay: 96000.0
*/

