Package com.deitel.jhtp6.jsp.beans

Examples of com.deitel.jhtp6.jsp.beans.Rotator


public class Time1PackageTest
{
   public static void main( String args[] )
   {
      // create and initialize a Time1 object
      Time1 time = new Time1(); // calls Time1 constructor

      // output string representations of the time
      System.out.print( "The initial universal time is: " );
      System.out.println( time.toUniversalString() );
      System.out.print( "The initial standard time is: " );
      System.out.println( time.toString() );
      System.out.println(); // output a blank line

      // change time and output updated time
      time.setTime( 13, 27, 6 );
      System.out.print( "Universal time after setTime is: " );
      System.out.println( time.toUniversalString() );
      System.out.print( "Standard time after setTime is: " );
      System.out.println( time.toString() );
      System.out.println(); // output a blank line

      // set time with invalid values; output updated time
      time.setTime( 99, 99, 99 );
      System.out.println( "After attempting invalid settings:" );
      System.out.print( "Universal time: " );
      System.out.println( time.toUniversalString() );
      System.out.print( "Standard time: " );
      System.out.println( time.toString() );
   } // end main
View Full Code Here


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

      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
         {
            // retrieve data to be output
            record.setAccount( input.nextInt() ); // read account number
            record.setFirstName( input.next() ); // read first name
            record.setLastName( input.next() ); // read last name
            record.setBalance( input.nextDouble() ); // read balance

            if ( record.getAccount() > 0 )
            {
               // write new record
               output.format( "%d %s %s %.2f\n", record.getAccount(),
                  record.getFirstName(), record.getLastName(),
                  record.getBalance() );
            } // end if
            else
            {
               System.out.println(
                  "Account number must be greater than 0." );
View Full Code Here

   // read record from file
   public void readRecords()
   {
      // object to be written to screen
      AccountRecord record = new AccountRecord();

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

      try // read records from file using Scanner object
      {
         while ( input.hasNext() )
         {
            record.setAccount( input.nextInt() ); // read account number
            record.setFirstName( input.next() ); // read first name
            record.setLastName( input.next() ); // read last name
            record.setBalance( input.nextDouble() ); // read balance

            // 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 ( NoSuchElementException elementException )
      {
         System.err.println( "File improperly formed." );
View Full Code Here

   // read records from file and display only records of appropriate type
   private void readRecords()
   {
      // object to be written to file
      AccountRecord record = new AccountRecord();

      try // read records
      {    
         // open file to read from beginning
         input = new Scanner( new File( "clients.txt" ) );

         while ( input.hasNext() ) // input the values from the file
         {
            record.setAccount( input.nextInt() ); // read account number
            record.setFirstName( input.next() ); // read first name
            record.setLastName( input.next() ); // read last name
            record.setBalance( input.nextDouble() ); // read balance

            // if proper acount type, display record
            if ( shouldDisplay( record.getBalance() ) )
               System.out.printf( "%-10d%-12s%-12s%10.2f\n",
                  record.getAccount(), record.getFirstName(),
                  record.getLastName(), record.getBalance() );
         } // end while
      } // end try
      catch ( NoSuchElementException elementException )
      {
         System.err.println( "File improperly formed." );
View Full Code Here

   } // end method openFile

   // read record from file
   public void readRecords()
   {
      AccountRecordSerializable record;
      System.out.printf( "%-10s%-12s%-12s%10s\n", "Account",
         "First Name", "Last Name", "Balance" );

      try // input the values from the file
      {
         while ( true )
         {
            record = ( AccountRecordSerializable ) input.readObject();

            // 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 endOfFileException )
      {
         return; // end of file was reached
View Full Code Here

   } // 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
            {
View Full Code Here

   } // 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

      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

   // 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

  
   // 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

TOP

Related Classes of com.deitel.jhtp6.jsp.beans.Rotator

Copyright © 2018 www.massapicom. 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.