Write a Java program that calculates and prints the monthly paycheck for an empl
ID: 3629636 • Letter: W
Question
Write a Java program that calculates and prints the monthly paycheck for an employees. The net pay is calculated after taking the following deductions:Federal Income Tax: 15%
State Tax 3.5%
Social Security Tax 5.7%
Medicare Tax 2.75%
Health Insurance $75.00
Your program should prompt the user to input the gross amount and the employee name.The output will be stored in a file. Format your output to have 2 decimal places.
The output as follows:
Allison Nields
Gross Amount: $
Federal Tax $
Social Security Tax $
Medicare Tax $
Health Insurance $
Net Pay $
Explanation / Answer
public static void main (String[] args) throws FileNotFoundException { PrintWriter outFile = new PrintWriter("info.out"); //declare variables double fedTax = .15; double stateTax = .035; double ssTax = .0575; double medTax = .0275; double penPlan = .05; double healthIns = 75; double netPay; double gross; double fedOut; double stateOut; double ssOut; double medOut; double penOut; double totalTax; String name; String grossPay; //prompt user name = JOptionPane.showInputDialog("Enter your first and last name: "); grossPay = JOptionPane.showInputDialog("Enter your gross amount: "); gross = Double.parseDouble(grossPay); outFile.println(name); //calculate taxes to take out fedOut = gross * fedTax; stateOut = gross * stateTax; ssOut = gross * ssTax; medOut = gross * medTax; penOut = gross * penPlan; totalTax = fedOut + stateOut + ssOut + medOut + penOut; // calculate net pay netPay = gross - totalTax; // display results outFile.println("name"); outFile.printf("Gross Amount: %.2f %n", gross); outFile.printf("Federal Tax: %.2f %n", fedOut); outFile.printf("State Tax: %.2f %n", stateOut); outFile.printf("Social Security Tax: %.2f %n", ssOut); outFile.printf("Medicare/Medicaid Tax: %.2f %n", medOut); outFile.printf("Pension Plan: %.2f %n", penOut); outFile.printf("Health Insurance: %.2f %n",healthIns); outFile.printf("Net Pay: %.2f %n", netPay); outFile.close(); //outfile close }//class close }//static void main close
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.