Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Unreported exception java.io.FileNotFOundException

843810Jun 1 2007 — edited Jun 1 2007
Please help me out with this, I'm new to Java and I can not figure this one out. I also tried it by including throw Exception after the args statement and it was able to create the file but nothing printed in it.

Thanks

Error:
unreported exception java.io.FileNotFOundException; must be caught or declared to be thrown

occurs on line 28
PrintWriter outfile = new PrintWriter("f:\\paycheckinfo.doc");

import javax.swing.JOptionPane;
import java.text.DecimalFormat;
import java.util.*;
import java.io.*;


public class paycheck
{

public static void main (String[] args)
{
//declare variables
double grossamt, net;
double federal=.15;
double state=.035;
double socsec=.0575;
double medicare=.0275;
double pension=.05;
double insur= 75.00;

String employee, inputStr2, outputStr;

DecimalFormat twoDecimal=
new DecimalFormat("0.00");

PrintWriter outFile = new PrintWriter("f:\\paycheckinfo.doc");
//get input

employee = JOptionPane.showInputDialog
("Enter the employee's First and Last Name. Ex: Sue Smith: ");


inputStr2 = JOptionPane.showInputDialog
("Enter the employees paychecks gross amount. Ex. 75.45");

grossamt = Double.parseDouble(inputStr2);


//formulas
federal= (grossamt * federal);
state= (grossamt*state);
socsec=(grossamt*socsec);
medicare=(grossamt * medicare);
pension=(grossamt * pension);
net=(grossamt-(federal+state+socsec+medicare+insur));
//output

outFile.println("" + employee + "\n" +
"Gross Amount: \t $" + grossamt + "\n"
+ "Federal Tax: \t $" + twoDecimal.format(federal) + "\n"
+ "State Tax: \t $" + twoDecimal.format(state) + "\n"
+ "Social Security Tax: \t $" + twoDecimal.format(socsec) + "\n"
+ "Meidcare/Medicaid Tax: \t $" + twoDecimal.format(medicare) + "\n"
+ "Pension Plan : \t $" + twoDecimal.format(pension) + "\n"
+ "Health Insurance: \t $" + twoDecimal.format(insur) + "\n"
+ "Net Pay: \t $" + twoDecimal.format(net));

outFile.close();

System.exit(0);
}

}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 29 2007
Added on Jun 1 2007
1 comment
557 views