(1) Write a Java program that calculates and prints the monthly paycheck for an
ID: 3653016 • Letter: #
Question
(1) 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 (2) 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: Ryan smith 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
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.