Note that there are some explanatory texts on larger screens.

plurals
  1. POJOptionPane with file output
    primarykey
    data
    text
    <p>I'm new to Java. I'm taking an online class this semester. The book which we are using isn't the greatest. I've tried searching around for answers online, but I'm coming up short. Maybe one of you guys can help me out :)</p> <p>Basically the program below is suppose to prompt the user to enter info, the program then calculates the deductions and outputs the info to a .txt file. It runs and complies without error. The dialog boxes pop up, but no data is being written to the file. The .txt file is saved in the same folder btw. Any ideas?</p> <pre><code>import java.io.*; import java.util.*; import javax.swing.JOptionPane; public class PaycheckCalculator { static final double FEDERAL_TAX = .15, STATE_TAX = .035, SOCIAL_SECURITY = .0575, MEDICARE_MEDICAID = .0275,PENSION = .05; static final int HEALTH_INSURANCE = 75; public static void main (String[] args) throws FileNotFoundException { String employeeName; String inputStr; double grossPay, netPay, federal, state, social, medicare, pension; int healthInsurance; PrintWriter outFile = new PrintWriter ("paycalc.txt"); employeeName = JOptionPane.showInputDialog ("Please enter your name: "); inputStr = JOptionPane.showInputDialog ("Please enter your monthly gross pay: "); grossPay = Double.parseDouble (inputStr); federal = (grossPay * FEDERAL_TAX); state = (grossPay * STATE_TAX); social = (grossPay * SOCIAL_SECURITY); medicare = (grossPay * MEDICARE_MEDICAID); pension = (grossPay * PENSION); netPay = (grossPay - federal - state - social - medicare - pension - HEALTH_INSURANCE); outFile.println (employeeName); outFile.printf ("Gross Amount: %.2f%n", grossPay); outFile.printf ("Federal Tax: %.2f%n", federal); outFile.printf ("State Tax: %.2f%n", state); outFile.printf ("Social Security Tax: %.2f%n", social); outFile.printf ("Medicare\\Medicaid Tax: %.2f%n", medicare); outFile.printf ("Pension Plan: %.2f%n", pension); outFile.printf ("Health Insurance: $" + HEALTH_INSURANCE); outFile.printf ("Net Pay: %.2f%n", netPay); System.exit(0); outFile.close(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload