} // end method openFile
// add records to file
public void addRecords()
{
AccountRecordSerializable record; // object to be written to file
int accountNumber = 0; // account number for record object
String firstName; // first name for record object
String lastName; // last name for record object
double balance; // balance for record object
Scanner input = new Scanner( System.in );
System.out.printf( "%s\n%s\n%s\n%s\n\n",
"To terminate input, type the end-of-file indicator ",
"when you are prompted to enter input.",
"On UNIX/Linux/Mac OS X type <ctrl> d then press Enter",
"On Windows type <ctrl> z then press Enter" );
System.out.printf( "%s\n%s",
"Enter account number (> 0), first name, last name and balance.",
"? " );
while ( input.hasNext() ) // loop until end-of-file indicator
{
try // output values to file
{
accountNumber = input.nextInt(); // read account number
firstName = input.next(); // read first name
lastName = input.next(); // read last name
balance = input.nextDouble(); // read balance
if ( accountNumber > 0 )
{
// create new record
record = new AccountRecordSerializable( accountNumber,
firstName, lastName, balance );
output.writeObject( record ); // output record
} // end if
else
{