Question
I need to write a interactive Java payroll application that calculates the net pay for a factory worker. The program prompts the user for skill level and hours worked, as well as appropriate insurance and retirement options for the employee's skill level category. The application displays: (1) the hours worked, (2) the hourly pay rate, (3) the regular pay for 40 hours, (4) the overtime pay, (5) the total of regular and overtime pay, and (6) the total itemized deductions. If the deductions exceed the gross pay, display an error message; otherwise, calculate and display (7) the net pay after all the deductions have been subtracted from the gross.
I also need to:
Explanation / Answer
import java.util.*; import javax.swing.JOptionPane; public class payroll{ public static void main(String[] args) { double hoursWorked = 0; //At zero hour all values are 0 double payRate = 0; double overTime = 0; //hoursWorked - 40; //overTime + 40 = hoursWorked double grossPay= hoursWorked * payRate; //double grossPay1 = grossPay + (overTime * ((payRate*3)/2)); //double grossPay += (hoursWorked - 40) * payRate*3/2; payRate = 0; grossPay = hoursWorked + payRate; grossPay =grossPay + (overTime * payRate*1.5); Scanner input = new Scanner(System.in); String name = JOptionPane.showInputDialog( "What is your name?" ); //Added for proj 3 String message = String.format( "Welcome, %s, to the payroll system!", name ); JOptionPane.showMessageDialog( null, message ); System.out.println("Enter your pay rate:"); payRate = input.nextDouble(); System.out.println("Enter your hours per week:"); hoursWorked = input.nextDouble(); //over time hour -->OT if ( hoursWorked 40) { hoursWorked = overTime + 40; overTime = hoursWorked - 40; grossPay = grossPay + ( overTime * payRate*1.5); // grossPay_OT = grossPay + (hoursWorked - 40) * payRate*3/2; System.out.println( "Your worked hours with OT: " + hoursWorked + " this week, your gross pay: $" +grossPay); } } /*String message = String.format( "Exit, %s, the payroll system!", name ); JOptionPane.showMessageDialog( null, message );*/ }