(Payroll) Write a program that reads the following information and prints payroll statements in show message dialog box.
These are the inputs:
Employees Full Name (e.g. Mohammed Al Zakwani)
Numbers of Hours worked in a week (e.g. 40 hours)
Hourly Pay Rate (e.g. 6.75)
Federal Tax withholding rate (e.g. 20%)
State Tax withholding rate (e.g. 9%)
You should calculate:
Gross Pay = hourly pay rate * numbers of hours worked in a week.
Federal Tax withholding = Federal Tax withholding rate * gross pay
State Tax withholding = State Tax withholding rate * gross pay
Total Deductions = Federal Tax withholding + State Tax withholding
Net Pay = Gross Pay + Total Deductions
Output should be
Employees Full Name: Mohammed Al Zakwani
Numbers of Hours worked in a week: 40 hours
Hourly Pay Rate: $ 6.75
Gross Pay: $270
Deductions:
Federal Tax withholding (20%): $54
State Tax withholding rate (9%) : $24.3
Total Deductions: $78.3
Net Pay: $191.7
I tried to do as below but i'm getting alot of error;
Expand|Select|Wrap|Line Numbers
- import java.util.Scanner;
- class payroll {
- {
- public static void main(String[] args)
- {
- Scanner input = new Scanner(System.in);
- System.out.println("Enter employee's name:");
- String employee = input.next();
- System.out.println("Enter number of hours worked:");
- double hours = input.nextDouble();
- System.out.println("Enter hourly pay rate:");
- double pay = input.nextDouble();
- double gross_pay = pay * hours;
- System.out.println("Enter federal tax withholding rate:");
- double fedtax = input.nextDouble();
- double fedtaxr = fedtax * 0.20;
- System.out.println("Enter state tax withholding rate:");
- double statetax = input.nextDouble();
- double statetaxr = statetax * 0.20;
- double deductions = fedtaxr + statetaxr;
- double total_pay = gross_pay - deductions;
- System.out.println("Employee name: " + employee);
- System.out.println("Hours worked: " + hours);
- System.out.println(" Enter payrate: " + pay);
- System.out.println(" Enter gross pay: " + gross_pay);
- System.out.println(" Deductions: ");
- System.out.println("\t Federdal Withholding (20.0%): " + fedtaxr);
- System.out.println("\t State Withholding (9.0%)" + statetaxr);
- System.out.println("\t Total deductions:" + deductions);
- System.out.println("Total pay: " + total_pay);
- }
- }