Source of PayableInterfaceTest.java


  1: // Fig. 10.15: PayableInterfaceTest.java
  2: // Tests interface Payable.
  3: 
  4: public class PayableInterfaceTest 
  5: {
  6:    public static void main( String args[] )
  7:    {
  8:       // create four-element Payable array
  9:       Payable payableObjects[] = new Payable[ 4 ];
 10:       
 11:       // populate array with objects that implement Payable
 12:       payableObjects[ 0 ] = new Invoice( "01234", "seat", 2, 375.00 );
 13:       payableObjects[ 1 ] = new Invoice( "56789", "tire", 4, 79.95 );
 14:       payableObjects[ 2 ] = 
 15:          new SalariedEmployee( "John", "Smith", "111-11-1111", 800.00 );
 16:       payableObjects[ 3 ] = 
 17:          new SalariedEmployee( "Lisa", "Barnes", "888-88-8888", 1200.00 );
 18: 
 19:       System.out.println( 
 20:          "Invoices and Employees processed polymorphically:\n" ); 
 21: 
 22:       // generically process each element in array payableObjects
 23:       for ( Payable currentPayable : payableObjects )
 24:       {
 25:          // output currentPayable and its appropriate payment amount
 26:          System.out.printf( "%s \n%s: $%,.2f\n\n", 
 27:             currentPayable.toString(), 
 28:             "payment due", currentPayable.getPaymentAmount() ); 
 29:       } // end for
 30:    } // end main
 31: } // end class PayableInterfaceTest
 32: 
 33: 
 34: /**************************************************************************
 35:  * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and               *
 36:  * Pearson Education, Inc. All Rights Reserved.                           *
 37:  *                                                                        *
 38:  * DISCLAIMER: The authors and publisher of this book have used their     *
 39:  * best efforts in preparing the book. These efforts include the          *
 40:  * development, research, and testing of the theories and programs        *
 41:  * to determine their effectiveness. The authors and publisher make       *
 42:  * no warranty of any kind, expressed or implied, with regard to these    *
 43:  * programs or to the documentation contained in these books. The authors *
 44:  * and publisher shall not be liable in any event for incidental or       *
 45:  * consequential damages in connection with, or arising out of, the       *
 46:  * furnishing, performance, or use of these programs.                     *
 47:  *************************************************************************/