close

public class CommissionEmployee extends Object

{

   private String firstName;
   private String lastName;
   private String socialSecurityNumber;
   private double grossSales;
   private double commissionRate;

   public CommissionEmployee ( String first, String last, String ssn,
                               double sales, double rate )

   {

      firstName = first;
      lastName = last;
      socialSecurityNumber = ssn;
      setGrossSales(sales);
      setCommissionRate(rate);

   }

   public void setFirstName( String first )

   {

      firstName = first;

   }

   public String getFirstName()

   {

      return firstName;

   }

   public void setLastName( String last )

   {

      lastName = last;

   }

   public String getLastName()

   {

      return lastName;

   }

   public void setSocialSecurityNumber( String ssn )

   {

      socialSecurityNumber = ssn;

   }

   public String getsocialSecurityNumber()

   {

      return socialSecurityNumber;

   }

   public void setGrossSales( double sales )

   {

      grossSales = ( sales

   }

   public double getGrossSales()

   {

      return grossSales;

   }

   public void setCommissionRate( double rate )

   {

      commissionRate = ( rate > 0.0 && rate

   }

   public double getCommissionRate()

   {

      return commissionRate;

   }

   public double earnings()

   {

      return commissionRate * grossSales;

   }

   public String toString()

   {

      return String.format( "%s: %s %s \n%s: %s\n%s: %.2f\n%s: %.2f" ,
         "姓名", firstName, lastName,
         "身份證號碼", socialSecurityNumber,
         "銷售毛額", grossSales,
         "抽佣比例", commissionRate);


   }

}




public class CommissionEmployeeTest

{

   public static void main ( String args[] )

   {

      CommissionEmployee employee =
      new CommissionEmployee( "Sue", "Jones", "222-22-2222", 10000, .06 );

      System.out.println(
         "Employee information obtained by get methods: \n" );
      System.out.printf("%s %s\n", "First name is",employee.getFirstName() );
      System.out.printf("%s %s\n", "Last name is",employee.getLastName() );
      System.out.printf("%s %s\n", "Social security number is",employee.getGrossSales() );
      System.out.printf("%s %.2f\n", "Gross sales is",employee.getGrossSales() );
      System.out.printf("%s %.2f\n", "Commission rate is",employee.getCommissionRate() );

      employee.setGrossSales( 500 );
      employee.setCommissionRate( .1 );

      System.out.printf("\n%s:\n\n%s\n",
         "Updated employee information obtained by to String" , employee );

   }

}

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 a25561970 的頭像
    a25561970

    萬花筒

    a25561970 發表在 痞客邦 留言(1) 人氣()