-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommissionEmployee.java
56 lines (45 loc) · 1.76 KB
/
CommissionEmployee.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Nickolas Berrie CSIS 312 Polymorphism and Inheritence.
package payrollsystem;
public class CommissionEmployee extends Employee
{
private double grossSales; // gross weekly sales
private double commissionRate; // commission percentage
// five-argument constructor
public CommissionEmployee( String first, String last, String ssn, double grossSales, double commissionRate )
{
super( first, last, ssn);
if (commissionRate <= 0.0 || commissionRate >=1.0)//validate rate
throw new IllegalArgumentException(
"Commission rate must be > 0.0 and < 1.0");
if (grossSales < 0.0)//validate sales
throw new IllegalArgumentException(
"Gross sales must be >= 0.0");
this.grossSales = grossSales;
this.commissionRate = commissionRate;
} // end five-argument CommissionEmployee constructor
// return commission rate
public double returnCommissionRate()
{
return commissionRate;
} // end method getCommissionRate
// return gross sales amount
public double returnGrossSales()
{
return grossSales;
} // end method getGrossSales
// calculate earnings; override abstract method earnings in Employee
@Override
public double earnings()
{
return returnCommissionRate() * returnGrossSales();
} // end method earnings
// return String representation of CommissionEmployee object
@Override
public String toString()
{
return String.format( "%s: %s\n%s: $%,.2f; %s: %.2f",
"commission employee", super.toString(),
"gross sales", returnGrossSales(),
"commission rate", returnCommissionRate() );
} // end method toString
} // end class CommissionEmployee