Page 570 - Introduction to Programming with Java: A Problem Solving Approach
P. 570

                536 Chapter 13 Inheritance and Polymorphism
 /********************************************************
*
Commission.java
Dean & Dean
This inteface specifies a common attribute
and declares common behavior of commissioned employees.
********************************************************/
*
*
*
*
interface Commission
{
}
double COMMISSION_RATE = 0.10;
void addSales(double sales);
// end interface Commission
Figure 13.14 An interface for use with an enhanced version of the Payroll program
 /****************************************************************
*
Commissioned.java
Dean & Dean
This class represents employees on straight commission.
****************************************************************/
          Apago PDF Enhancer
private double sales = 0.0;
*
*
*
public class Commissioned extends Employee2 implements Commission
{
//*************************************************************
public Commissioned(String name)
{
super(name);
this.sales = sales;
} // end constructor
//*************************************************************
public void addSales(double sales) ⎫ {⎪
⎬ this.sales += sales; ⎪
   } // end addSales ⎭
//*************************************************************
public double getPay() ⎫ {⎪
double pay = COMMISSION_RATE * sales; ⎪ ⎬ sales = 0.0; ⎪ return pay; ⎪ ⎭
    }
// end class Commissioned
} // end getPay
The interface requires this method definition.
Inheritance from an abstract class requires this method definition.
 The interface supplies this constant value.
Figure 13.15 Class defining straight-commission employees in enhanced Payroll program















































   568   569   570   571   572