Examples of RandomAccessAccountRecord


Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

   } // end method openFile
  
   // read and display records
   public void readRecords()
   {
      RandomAccessAccountRecord record = new RandomAccessAccountRecord();

      System.out.printf( "%-10s%-15s%-15s%10s\n", "Account",
         "First Name", "Last Name", "Balance" );

      try // read a record and display
      {
         while ( true )
         {
            do
            {
               record.read( input );
            } while ( record.getAccount() == 0 );

            // display record contents
            System.out.printf( "%-10d%-12s%-12s%10.2f\n",
               record.getAccount(), record.getFirstName(),
               record.getLastName(), record.getBalance() );
         } // end while
      } // end try
      catch ( EOFException eofException ) // close file
      {
         return; // end of file was reached
View Full Code Here

Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

      try // open file for reading and writing
      {          
         file = new RandomAccessFile( "clients.dat", "rw" );

         RandomAccessAccountRecord blankRecord =
            new RandomAccessAccountRecord();

         // write 100 blank records
         for ( int count = 0; count < NUMBER_RECORDS; count++ )
            blankRecord.write( file );

         // display message that file was created
         System.out.println( "Created file clients.dat." );

         System.exit( 0 ); // terminate program
View Full Code Here

Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

   // add records to file
   public void addRecords()
   {
      // object to be written to file
      RandomAccessAccountRecord record = new RandomAccessAccountRecord();

      int accountNumber = 0; // account number for AccountRecord object
      String firstName; // first name for AccountRecord object
      String lastName; // last name for AccountRecord object
      double balance; // balance for AccountRecord 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 %s\n%s", "Enter account number (1-100),",
         "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 && accountNumber <= NUMBER_RECORDS )
            {
               record.setAccount( accountNumber );
               record.setFirstName( firstName );
               record.setLastName( lastName );
               record.setBalance( balance );

               output.seek( ( accountNumber - 1 ) * // position to proper
                  RandomAccessAccountRecord.SIZE ); // location for file
               record.write( output );
            } // end if
            else
               System.out.println( "Account must be between 0 and 100." );
         } // end try
         catch ( IOException ioException )
View Full Code Here

Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

  
   // get a record from the file
   public RandomAccessAccountRecord getRecord( int accountNumber )
      throws IllegalArgumentException, NumberFormatException, IOException
   {
      RandomAccessAccountRecord record = new RandomAccessAccountRecord();

      if ( accountNumber < 1 || accountNumber > 100 )
         throw new IllegalArgumentException( "Out of range" );

      // seek appropriate record in file
      file.seek( ( accountNumber - 1 ) * RandomAccessAccountRecord.SIZE );
     
      record.read( file );

      return record;
   } // end method getRecord
View Full Code Here

Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

  
   // update record in file
   public void updateRecord( int accountNumber, double transaction )
      throws IllegalArgumentException, IOException
   {
      RandomAccessAccountRecord record = getRecord( accountNumber );

      if ( record.getAccount() == 0 )
         throw new IllegalArgumentException( "Account does not exist" );

      // seek appropriate record in file
      file.seek( ( accountNumber - 1 ) * RandomAccessAccountRecord.SIZE );  

      record = new RandomAccessAccountRecord(
         record.getAccount(), record.getFirstName(),
         record.getLastName(), record.getBalance() + transaction );
        
      record.write( file ); // write updated record to file     
   } // end method updateRecord
View Full Code Here

Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

   // add record to file
   public void newRecord( int accountNumber, String firstName,
      String lastName, double balance )
      throws IllegalArgumentException, IOException
   {
      RandomAccessAccountRecord record = getRecord( accountNumber );
     
      if ( record.getAccount() != 0 )
         throw new IllegalArgumentException( "Account already exists" );

      // seek appropriate record in file
      file.seek( ( accountNumber - 1 ) * RandomAccessAccountRecord.SIZE );  

      record = new RandomAccessAccountRecord( accountNumber,
         firstName, lastName, balance );
        
      record.write( file ); // write record to file     
   } // end method newRecord
View Full Code Here

Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

  
   // delete record from file
   public void deleteRecord( int accountNumber )
      throws IllegalArgumentException, IOException
   {
      RandomAccessAccountRecord record = getRecord( accountNumber );
     
      if ( record.getAccount() == 0 )
         throw new IllegalArgumentException( "Account does not exist" );
     
      // seek appropriate record in file
      file.seek( ( accountNumber - 1 ) * RandomAccessAccountRecord.SIZE );

      // create a blank record to write to the file
      record = new RandomAccessAccountRecord();
      record.write( file );     
   } // end method deleteRecord
View Full Code Here

Examples of com.deitel.jhtp6.ch14.RandomAccessAccountRecord

   } // end method deleteRecord

   // read and display records
   public void readRecords()
   {
      RandomAccessAccountRecord record = new RandomAccessAccountRecord();

      System.out.printf( "%-10s%-15s%-15s%10s\n", "Account",
         "First Name", "Last Name", "Balance" );
  
      try // read a record and display
      {
         file.seek( 0 );

         while ( true )
         {
            do
            {
               record.read( file );
            } while ( record.getAccount() == 0 );

            // display record contents
            System.out.printf( "%-10d%-15s%-15s%10.2f\n",
               record.getAccount(), record.getFirstName(),
               record.getLastName(), record.getBalance() );
         } // end while
      } // end try
      catch ( EOFException eofException ) // close file
      {
         return; // end of file was reached
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.