Unreported exception java.io.FileNotFOundException

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);

}

}

[2213 byte] By [jkbatchosa] at [2007-11-27 6:09:28]
# 1

Never mind fixed it!

import javax.swing.JOptionPane;

> import java.text.DecimalFormat;

> import java.util.*;

> import java.io.*;

>

>

> public class paycheck

> {

>

> public static void main (String[] args)

throws FileNotFoundException

> {

> //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");

>

Scanner inFile =

new Scanner(new FileReader("f:\\paycheckinfo.doc"));//get input

>

> employee = JOptionPane.showInputDialog

> ("Enter the employee's First and Last Name.

> t Name. Ex: Sue Smith: ");

>

>

> inputStr2 = JOptionPane.showInputDialog

> ("Enter the employees paychecks gross amount.

> 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)

> l) + "\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);

> }

>

> }

jkbatchosa at 2007-7-12 17:13:22 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...