cant find the error?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rleathem
    New Member
    • Dec 2009
    • 1

    cant find the error?

    Code:
    import java.io.*;
    import javax.swing.JOptionPane;
    
    public class Errors
    {
      	public static void main(String[] args)
      	{
    
    		String line;
    		int startMiles = 0;
    		double endMiles = 0;
    		double gallons = 0;
    		boolean done = false;
    
    		while(!done)
    		{
    			try
    			{
    				String start = JOptionPane.showInputDialog(null,"Enter starting mileage: " );
    				startMiles = Integer.parseInt(start);
    
    				String end =JOptionPane.showInputDialog(null,"Enter ending mileage: " );
    				endMiles = Integer.parseInt(end);
    
    				if (endMiles<=startMiles) throw new NumberFormatException e();
    
    				String amount = JOptionPane.showInputDialog(null,"Enter number of gallons: " );
    				gallons = Integer.parseInt(amount);
    				done = true;
    			}
    			catch(NumberFormatException e)
    			{
    				JOptionPane.showMessageDialog(null, "Your ending mileage,",endMiles +", must be greater than your starting mileage, " + startMiles, "Error in Mileage",JOptionPane.INFORMATION_MESSAGE);
    			}
    		public static void finish()
    		{
    		JOptionPane.showMessageDialog(null,"Miles per gallon is "+ (endMiles - startMiles)/gallons);
    		}
    		}
    	}
    }
    Last edited by Frinavale; Dec 8 '09, 04:16 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    What IS the error?

    You can't just post a bunch of code and title the thread "Can't find the error". It's unfair to expect people to sift through tons of code to find the few lines that you are having problems. Never mind that you haven't even provided any explanation as to what the problem is!

    Please specify what you are having problems with, what (if any) errors you are getting, and what you have tried to solve the problem. Don't just post a bunch of code and expect us to figure out what it is, what's wrong with it, and what you are having problems with.

    Please check out the posting guidelines for more information on how to ask a question.

    -Frinny

    Comment

    Working...