Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Need help with input/output error

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help with input/output error

    I am writing a program that needs me to input the assessed value of a home and then the output should be stored in a file. The program deals with property tax. I'm getting the error

    Exception in thread "main" java.util.InputMismatchException
    at java.util.Scanner.throwFor(Scanner.java:840)
    at java.util.Scanner.next(Scanner.java:1461)
    at java.util.Scanner.nextDouble(Scanner.java:2387)
    at Problem4.main(Problem4.java:33)

    Here is my full code


    // Stefan Springhetti
    // Problem4
    // 2/1/2001
     
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
     
    public class Problem4 {
     
    			public static void main(String[] args)
    											throws FileNotFoundException
    			{
    			String inputStr;
    			double assessedValue; 
    			double taxableAmount;
    			double taxRate;
    			double propertyTax;
     
     
    			taxableAmount = .92 * assessedValue;
    			taxRate = 1.05;
    			propertyTax = 1.05 * 92;
     
    			Scanner inFile =
    				new Scanner(new FileReader("tax.dat"));
     
    			PrintWriter outFile = new PrintWriter("output.dat");
     
    			inputStr = JOptionPane.showInputDialog
    									("Enter the assessed value");
    			assessedValue = Double.parseDouble(inputStr);
     
     
    			outFile.printf("Assesed Value: $" + String.format("%.2f", assessedValue) + "\n"
    			+ "Taxable Amount: $" +  String.format("%.2f", taxableAmount)+ "\n"
    			+ "Tax Rate: $" + String.format("%.2f", taxRate) + "\n" 
    			+ "Property Tax: $" + String.format("%.2f", propertyTax));
     
     
    			outFile.close(); 
     
    			}
    }
    Last edited by stefan2892; February 6th, 2011 at 05:01 PM.


  2. #2
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with input/output error

    I'm new to java, so sorry if this seems like a dumb question

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with input/output error

    I realize I dont need the inFile, but I cannot figure out the error. Help would be greatly appreciated

  4. #4
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Question Re: Need help with input/output error

    when i executed this program on my machine , its executing fine.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  5. #5
    Junior Member
    Join Date
    Feb 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help with input/output error

    Well when I'm trying to run it on J Grasp I get the error message. I know the window pops up fine but after that is when I get the error message

Similar Threads

  1. Creating Methods for Input/Output Files
    By PapaGL0VE in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: November 17th, 2010, 09:07 AM
  2. [SOLVED] T_T [hellllppppp] Input/Output
    By bontet in forum File I/O & Other I/O Streams
    Replies: 9
    Last Post: October 29th, 2010, 11:32 AM
  3. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 25th, 2010, 08:34 PM
  4. Input/Output file help
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 23rd, 2010, 06:26 PM
  5. [SOLVED] java me how to: input - math operation - output
    By Lifer in forum Java ME (Mobile Edition)
    Replies: 3
    Last Post: April 7th, 2010, 05:36 PM