// Exceptions demo import javax.swing.JOptionPane; import java.io.IOException; public class GradeListTest { public static void main(String[] args) { String gradeString = ""; GradeList myGrades = new GradeList(); while (!(gradeString.equals("-1"))) { gradeString = JOptionPane.showInputDialog("Enter a grade between 0 and 100 [-1 to quit]"); try { if (!gradeString.equals("-1")) { try { myGrades.add(Integer.parseInt(gradeString)); } catch (NumberFormatException e) { System.out.println("NumberFormatException - only numbers allowed"); } } } catch (IllegalArgumentException exception1) { System.out.println(exception1); } catch (IllegalStateException exception2) { System.out.println(exception2); } catch (NullPointerException o) { System.out.println("NullPointerException - only numbers allowed"); gradeString = JOptionPane.showInputDialog("Enter a grade between 0 and 100 [-1 to quit]"); } } try { System.out.println("The grade average is " + myGrades.computeAverage()); } catch (ArithmeticException exception3) { System.out.println(exception3); } System.exit(0); } }