View Single Post
  #4 (permalink)  
Old 03-19-2008, 07:30 AM
hardwired hardwired is offline
Senior Member
 
Join Date: Jul 2007
Posts: 1,222
hardwired is on a distinguished road
Code:
public static void main(String[] args) { intro(); int numberOfStudents = 0; boolean succeded; do { succeded = true; String response = JOptionPane.showInputDialog("Enter number of students."); try { numberOfStudents = Integer.parseInt(response); } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null, "NFE: " + e.getMessage()); succeded = false; } } while(!succeded); String[] names = new String[numberOfStudents]; ... public static void getInput(String[] names, int[] scores) { ... String s = JOptionPane.showInputDialog("What is the students name?"); names[count] = s; s = JOptionPane.showInputDialog("Please enter a number."); // You can do the same here as above: guard this parseInt // method call with a try/catch statemnt and JOptioPane // notification. Incrementing the "count" variable may // need some attention/help. scores[count] = Integer.parseInt(s); } while(count++ < names.length-1); }
Reply With Quote