⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 payrollsystemtest.java

📁 java实例讲解, 编码分析. 多个案例集合做后一定让您有所长进
💻 JAVA
字号:
// Fig. 10.17: PayrollSystemTest.java
// Employee hierarchy test program.
import java.text.DecimalFormat;
import javax.swing.JOptionPane;

public class PayrollSystemTest {

   public static void main( String[] args ) 
   {
      DecimalFormat twoDigits = new DecimalFormat( "0.00" );

      // create Employee array
      Employee employees[] = new Employee[ 4 ];

      // initialize array with Employees
      employees[ 0 ] = new SalariedEmployee( "John", "Smith", 
         "111-11-1111", 800.00 );
      employees[ 1 ] = new CommissionEmployee( "Sue", "Jones", 
         "222-22-2222", 10000, .06 );
      employees[ 2 ] = new BasePlusCommissionEmployee( "Bob", "Lewis", 
         "333-33-3333", 5000, .04, 300 );
      employees[ 3 ] = new HourlyEmployee( "Karen", "Price", 
         "444-44-4444", 16.75, 40 );

      String output = "";

      // generically process each element in array employees
      for ( int i = 0; i < employees.length; i++ ) {
         output += employees[ i ].toString();

         // determine whether element is a BasePlusCommissionEmployee
         if ( employees[ i ] instanceof BasePlusCommissionEmployee ) {

            // downcast Employee reference to 
            // BasePlusCommissionEmployee reference
            BasePlusCommissionEmployee currentEmployee = 
               ( BasePlusCommissionEmployee ) employees[ i ];

            double oldBaseSalary = currentEmployee.getBaseSalary();
            output += "\nold base salary: $" + oldBaseSalary;      
            
            currentEmployee.setBaseSalary( 1.10 * oldBaseSalary );
            output += "\nnew base salary with 10% increase is: $" +
               currentEmployee.getBaseSalary();

         } // end if

         output += "\nearned $" + employees[ i ].earnings() + "\n";

      } // end for

      // get type name of each object in employees array
      for ( int j = 0; j < employees.length; j++ )
         output += "\nEmployee " + j + " is a " +
            employees[ j ].getClass().getName(); 

      JOptionPane.showMessageDialog( null, output );  // display output
      System.exit( 0 );

   } // end main

} // end class PayrollSystemTest

/**************************************************************************
 * (C) Copyright 1992-2003 by Deitel & Associates, Inc. and               *
 * Prentice Hall. All Rights Reserved.                                    *
 *                                                                        *
 * DISCLAIMER: The authors and publisher of this book have used their     *
 * best efforts in preparing the book. These efforts include the          *
 * development, research, and testing of the theories and programs        *
 * to determine their effectiveness. The authors and publisher make       *
 * no warranty of any kind, expressed or implied, with regard to these    *
 * programs or to the documentation contained in these books. The authors *
 * and publisher shall not be liable in any event for incidental or       *
 * consequential damages in connection with, or arising out of, the       *
 * furnishing, performance, or use of these programs.                     *
 *************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -