... 3
 4   public class CommissionEmployee extends Employee {
 5      private double grossSales; // gross weekly sales
 6      private double commissionRate; // commission percentage
 7
 8      // constructor
9      public CommissionEmployee(String firstName, String lastName,
10         String socialSecurityNumber, double grossSales,
11         double commissionRate) {
12         super(firstName, lastName, socialSecurityNumber);
13
14         if (commissionRate <= 0.0 || commissionRate >= 1.0) // validate
15            throw new IllegalArgumentException(
16               "Commission rate must be > 0.0 and < 1.0");
17         }
18
19         if (grossSales < 0.0) { // validate
20            throw new IllegalArgumentException("Gross sales must be >= 0.0");
21         }
22
23         this.grossSales = grossSales;
24         this.commissionRate = commissionRate;
25      }
26
27      // set gross ...

Get Java How To Program, Late Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.