... 24               "Enter end-of-file indicator to end input.");
25
26            while (input.hasNext()) { // loop until end-of-file indicator
27               try {
28                  // create new record
29                  Account record = new Account(input.nextInt(),
30                     input.next(), input.next(), input.nextDouble());
31
32                  // add to AccountList
33                  accounts.getAccounts().add(record);
34                }
35                catch (NoSuchElementException elementException) {
36                   System.err.println("Invalid input. Please try again.");
37                   input.nextLine(); // discard input so user can try again
38                }
39
40                System.out.print("? ");
41            }
42
43            // write AccountList's XML to output
44            JAXB.marshal(accounts, output);
45         }
46            catch (IOException ioException) {
47               System.err.println("Error opening file. Terminating.");
48            }
49         }
50   }
 Enter account number, first ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.