@@ -0,0 +1,1870 @@
+package chapter15;%0A%0Aimport java.io.IOException;%0Aimport java.io.ObjectOutputStream;%0Aimport java.nio.file.Files;%0Aimport java.nio.file.Paths;%0Aimport java.util.NoSuchElementException;%0Aimport java.util.Scanner;%0A%0Apublic class CreateSequentialFile %7B%0A%0A%09private static ObjectOutputStream output; // outputs data to file%0A%09%0A%09public static void main(String%5B%5D args) %7B%0A%09%09openFile();%0A%09%09addRecords();%0A%09%09closeFile();%0A%09%7D%0A%09%0A%09// open file clients.ser%0A%09public static void openFile() %7B%0A%09%09try %7B%0A%09%09%09output = new ObjectOutputStream(Files.newOutputStream(Paths.get(%22clients.ser%22)));%0A%09%09%7D catch (IOException ioException) %7B%0A%09%09%09System.err.println(%22Error opening file. Terminating.%22);%0A%09%09%09System.exit(1); //terminate the program%0A%09%09%7D%0A%09%7D%0A%09%0A%09// add records to file%0A%09public static void addRecords() %7B%0A%09%09Scanner input = new Scanner(System.in);%0A%09%09System.out.printf(%22%25sn%25s%25n? %22, %22Enter account number, first name, last name and balance.%22,%0A%09%09%09%09%09%09%09%09%09%09%22Enter end-of-file indicator to end input.%22);%0A%09%09%0A%09%09while (input.hasNext()) %7B // loop until end-of-file indicator%0A%09%09%09try %7B%0A%09%09%09%09// create new record; this example assumes valid input%0A%09%09%09%09Account record = new Account(input.nextInt(), input.next(), input.next(), input.nextDouble());%0A%09%09%09%09%0A%09%09%09%09// serialize record object into file%0A%09%09%09%09output.writeObject(record);%0A%09%09%09%7D catch (NoSuchElementException elementException) %7B%0A%09%09%09%09System.err.println(%22Invalid input. Please try again.%22);%0A%09%09%09%09input.nextLine(); // discard input so user can try again%0A%09%09%09%7D catch (IOException ioException) %7B%0A%09%09%09%09System.err.println(%22Error writing to file. Terminating.%22);%0A%09%09%09%09break;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09System.out.print(%22? %22);%0A%09%09%7D%0A%09%7D%0A%09%0A%09// close file and terminate application%0A%09public static void closeFile() %7B%0A%09%09try %7B%0A%09%09%09if (output != null)%0A%09%09%09%09output.close();%0A%09%09%7D catch (IOException ioException) %7B%0A%09%09%09System.err.println(%22Error closing file. Terminating.%22);%0A%09%09%7D%0A%09%7D%0A%09%0A%7D // end class CreateSequentialFile%0A

Create CreateSequentialFile.java