Question: JAVA programming Quesiton Federal overtime law requires employers to pay employees one and one-half times their regular rate of pay when employees work more than
JAVA programming Quesiton
Federal overtime law requires employers to pay employees one and one-half times their regular rate of pay when employees work more than forty hours during a work week. Write a program that will read in the number of hours an employee worked in a week, and the rate as input and then output the worker's gross income. From the worker's gross income, 14% is withheld for federal income tax, 8% is withheld for social security tax, 6% is withheld for state income tax, and 1% is withheld for local tax. If the worker has 3 or more dependents, then an additional $40 is withheld to cover the extra cost of health insurance beyond what the employers pay. The program should calculate and print the worker's net pay and each withholding amount.
This is what I have. It works, but when I enter less than 3 dependents, it still gives me 40$ for health insurance.
import java.util.Scanner; import java.io.*; public class Assignment1 { public static void main (String [] args)throws IOException { int Hours, Overtime, Dep; double Rate, Gross, Net, Ftax, SStax, Stax, Ltax, HIns; PrintWriter outfile = null; outfile = new PrintWriter (new FileOutputStream ("Worker's Net Income")); Scanner keyboard = new Scanner (System.in); System.out.println ("Enter the number of hours an employee worked during the week, the rate of pay, and the number of dependents"); Hours = keyboard.nextInt (); Rate = keyboard.nextDouble (); Dep = keyboard.nextInt (); if (Dep <= 3) { HIns = 0; } else { HIns = 40; } if (Hours <= 40) { Overtime = 0; Gross = Hours * Rate; } else { Overtime = Hours - 40; Gross = 40 * Rate + Overtime * Rate * 1.5; } Ftax = Gross * 0.14; SStax = Gross * 0.08; Stax = Gross * 0.06; Ltax = Gross * 0.01; HIns = 40; Net = Gross - Ftax - SStax - Stax - Ltax - HIns; System.out.println ("Federal Income Tax =" + Ftax); System.out.println ("State Security Tax =" + SStax); System.out.println ("State Income Tax =" + Stax); System.out.println ("Local Tax =" + Ltax); System.out.println ("Health Insurance =" + HIns); System.out.println ("Overtime =" + Overtime); System.out.println ("Gross Income =" + Gross); System.out.println ("Net Income =" + Net); outfile.println ("Federal Income Tax =" + Ftax); outfile.println ("State Security Tax =" + SStax); outfile.println ("State Income Tax =" + Stax); outfile.println ("Local Tax =" + Ltax); outfile.println ("Health Insurance =" + HIns); outfile.println ("Overtime =" + Overtime); outfile.println ("Gross Income =" + Gross); outfile.println ("Net Income =" + Net); outfile.close (); } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
