Climbing的专栏

Life is limited, but art is long

huang ClimbingID:hpdlzu80100
[修改头像]
1574次访问,排名2万外好友5人,关注者6
热爱生活,积极向上,流自己的汗,吃自己的饭!
hpdlzu80100的文章
原创 23 篇
翻译 0 篇
转载 2 篇
评论 0 篇
最近评论
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes
文章分类
收藏
    相册
    存档

    原创 薪水册测试类及结果(Payroll System modification)

    新一篇: 随机单词文章构造器(Random Term Paper Writer)

    //Payroll System Test, Java how to program 6/e, Exercise 10.9
    //Modified based on Fig. 10.9: PayrollSystemTest.java
    // Employee hierarchy test program.

    package PayrollSystem;

    import java.util.*;


      
    public class PayrollSystemTest
      {
         
    public static void main( String args[] )
         {
            
    // create subclass objects    
             Date birthday[]=new Date[5];
             birthday[
    0]=new Date(4,20,1980);
             birthday[
    1]=new Date(9,30,1980);
             birthday[
    2]=new Date(10,2,1982);
             birthday[
    3]=new Date(9,6,1979);
             birthday[
    4]=new Date(4,6,1979);
             
            SalariedEmployee salariedEmployee 
    =                                 
               
    new SalariedEmployee( "Jack""Michale""111-11-1111",birthday[0], 20 );  
            HourlyEmployee hourlyEmployee 
    =                                     
               
    new HourlyEmployee( "Karen""Price""222-22-2222", birthday[1],16.7540 );
            CommissionEmployee commissionEmployee 
    =                             
               
    new CommissionEmployee(                                          
               
    "Sue""Jones""333-33-3333", birthday[2],10000, .06 );                     
            BasePlusCommissionEmployee basePlusCommissionEmployee 
    =             
               
    new BasePlusCommissionEmployee(                                  
               
    "Bob""Lewis""444-44-4444", birthday[3],5000, .04300 );  
            PieceWorker pieceWorker 
    =             
                
    new PieceWorker(                                  
                
    "Eddy""Thomas""555-55-5555", birthday[4],10000, .5 ); 

            System.out.println( 
    "Employees processed individually: \n\n" );

            System.out.printf( 
    "%s %s: $%,.2f ",
               salariedEmployee, 
    "earned", salariedEmployee.earnings() );
            System.out.printf( 
    "%s %s: $%,.2f ",
               hourlyEmployee, 
    "earned", hourlyEmployee.earnings() );
            System.out.printf( 
    "%s %s: $%,.2f ",
               commissionEmployee, 
    "earned", commissionEmployee.earnings() );
            System.out.printf( 
    "%s %s: $%,.2f ",
               basePlusCommissionEmployee,
               
    "earned", basePlusCommissionEmployee.earnings() );
            System.out.printf( 
    "%s %s: $%,.2f ",
                    pieceWorker,
                    
    "earned", pieceWorker.earnings() );

            
    // create four-element Employee array
            Employee employees[ ] = new Employee[ 5 ];

            
    // initialize array with Employees          
            employees[ 0 ] = salariedEmployee;          
            employees[ 
    1 ] = hourlyEmployee;            
            employees[ 
    2 ] = commissionEmployee;        
            employees[ 
    3 ] = basePlusCommissionEmployee;
            employees[ 
    4 ] = pieceWorker;

            System.out.println( 
    "Employees processed polymorphically:\n\n" );

            
    // generically process each element in array employees
            
            
    for ( Employee currentEmployee : employees )
            {
               System.out.println( currentEmployee ); 
    // invokes toString

               
    // check birth month's consistency
               Calendar cal=new GregorianCalendar();
               
    int currentMonth=cal.get(Calendar.MONTH);
              
               
    if (currentEmployee instanceof PieceWorker)
                   System.out.printf(
    "%s %s ""You are great","I was a piece worker before.");
               
               
    if ( currentEmployee.getBirthMonth()==currentMonth+1)
               {
                  
    double bonus=100.00;
                  System.out.printf(
                     
    "Annual bonus is: $%,.2f ",
                     bonus);
                  System.out.printf(
                          
    "Total earning is: $%,.2f ", currentEmployee.earnings()+bonus );
               } 
    // end if
              
               
    else{
                   System.out.printf(
                              
    "earned $%,.2f ", currentEmployee.earnings() );
               }
               
                 
            } 
    // end for

            
    // get type name of each object in employees array
            for ( int j = 0; j < employees.length; j++ )      
               System.out.printf( 
    "Employee %d is a %s ", j, 
                  employees[ j ].getClass().getName() );      
         } 
    // end main
      } // end class PayrollSystemTest

     

    A snapshot of program execution:

    发表于 @ 2008年04月27日 18:52:38|评论(loading...)|编辑

    旧一篇: 自定义40位大整数类及测试类(Define a huge integer and implement its arithmetic operation)

    评论:没有评论。

    发表评论  


    登录
    Csdn Blog version 3.1a
    Copyright © Climbing