Expand|Select|Wrap|Line Numbers
- 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);
- }
- }
- }
- }