I need classes, for all figures except for 8.7. I have attached the instructions. Please make sure work is in accordance with the book How to program, late projects edition 11 and nothing extra and is

CSIS 212

Programming Assignment 8 Instructions


Exercise 10.12: Payroll Modification Modify the payroll system of Figs 10.4 –10.9 to include private instance variable birthdate in class Employee. Use class Date of Fig 8.7 to represent an employee’s birthday. Add get methods to class Date. Assume that payroll is processed once per month. Create an array of Employee variables to store references to the various employee objects. In a loop, calculate the payroll for each Employee (polymorphic ally), and add a $100.00 bonus to the persons payroll amount if the current month is the one in which the Employee’s birthdate occurs.

       

This assignment is due by 11:59 p.m. (ET) on Monday.    

Figures:

Fig 8.7
Fig.8.7 Date class declaration.
 1   // Fig. 8.7: Date.java
 2   // Date class declaration.
 3
 4   public class Date {
 5      private int month; // 1-12
 6      private int day; // 1-31 based on month
 7      private int year; // any year
 8
 9      private static final int[] daysPerMonth =
10         { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
11
12      // constructor: confirm proper value for month and day given the year
13      public Date(int month, int day, int year) {
14         // check if month in range
15         if (month <= 0 || month > 12)
16            throw new IllegalArgumentException(
17               "month (" + month + ") must be 1-12");
18         }
19
20         // check if day in range for month
21         if (day <= 0 ||
22            (day > daysPerMonth[month] && !(month == 2 && day == 29)))
23            throw new IllegalArgumentException("day (" + day +
24               ") out-of-range for the specified month and year");
25         }
26
27         // check for leap year if month is 2 and day is 29
28         if (month == 2 && day == 29 && !(year % 400 == 0 ||
29               (year % 4 == 0 && year % 100 != 0)))
30            throw new IllegalArgumentException("day (" + day +
31               ") out-of-range for the specified month and year");
32         }
33
34         this.month = month;
35         this.day = day;
36         this.year = year;
37
38         System.out.printf("Date object constructor for date %s%n", this);
39      }
40
41      // return a String of the form month/day/year
42      public String toString() {
43         return String.format("%d/%d/%d", month, day, year);
44      }
45   }
Fig 10.4
Fig.10.4 Employee abstract superclass.
 1   // Fig. 10.4: Employee.java
 2   // Employee abstract superclass.
 3
 4   public abstract class Employee {
 5      private final String firstName;
 6      private final String lastName;
 7      private final String socialSecurityNumber;
 8
 9      // constructor
10      public Employee(String firstName, String lastName,
11         String socialSecurityNumber) {
12         this.firstName = firstName;
13         this.lastName = lastName;
14         this.socialSecurityNumber = socialSecurityNumber;
15      }
16
17      // return first name
18      public String getFirstName() {return firstName;}
19
20      // return last name
21      public String getLastName() {return lastName;}
22
23      // return social security number
24      public String getSocialSecurityNumber() {return socialSecurityNumber;}
25
26      // return String representation of Employee object
27      @Override
28      public String toString() {
29         return String.format("%s %s%nsocial security number: %s",
30            getFirstName(), getLastName(), getSocialSecurityNumber());
31      }
32
33      // abstract method must be overridden by concrete subclasses
34      public abstract double earnings(); // no implementation here
35   }
Fig.10.5 SalariedEmployee concrete class extends abstract class Employee.
 1   // Fig. 10.5: SalariedEmployee.java
 2   // SalariedEmployee concrete class extends abstract class Employee.
 3
 4   public class SalariedEmployee extends Employee {
 5      private double weeklySalary;
 6
 7      // constructor
 8      public SalariedEmployee(String firstName, String lastName,
 9         String socialSecurityNumber, double weeklySalary) {
10         super(firstName, lastName, socialSecurityNumber);
11
12         if (weeklySalary < 0.0) {
13            throw new IllegalArgumentException(
14               "Weekly salary must be >= 0.0");
15         }
16
17         this.weeklySalary = weeklySalary;
18      }
19
20      // set salary
21      public void setWeeklySalary(double weeklySalary) {
22         if (weeklySalary < 0.0) {
23            throw new IllegalArgumentException(
24               "Weekly salary must be >= 0.0");
25         }
26
27         this.weeklySalary = weeklySalary;
28      }
29
30      // return salary
31      public double getWeeklySalary(){return weeklySalary;}
32
33      // calculate earnings; override abstract method earnings in Employee
34      @Override                                                          
35      public double earnings() {return getWeeklySalary();}                
36
37      // return String representation of SalariedEmployee object  
38      @Override                                                    
39      public String toString() {                                  
40         return String.format("salaried employee: %s%n%s: $%,.2f",
41            super.toString(), "weekly salary", getWeeklySalary());
42      }                                                            
43   }
Fig.10.6 HourlyEmployee class extends Employee.
 1   // Fig. 10.6: HourlyEmployee.java
 2   // HourlyEmployee class extends Employee.
 3
 4   public class HourlyEmployee extends Employee {
 5      private double wage; // wage per hour
 6      private double hours; // hours worked for week
 7
 8      // constructor
 9      public HourlyEmployee(String firstName, String lastName,
10         String socialSecurityNumber, double wage, double hours) {
11         super(firstName, lastName, socialSecurityNumber);
12
13         if (wage < 0.0) // validate wage
14            throw new IllegalArgumentException("Hourly wage must be >= 0.0");
15         }
16
17         if ((hours < 0.0) || (hours > 168.0)) { // validate hours
18            throw new IllegalArgumentException(
19               "Hours worked must be >= 0.0 and <= 168.0");
20         }
21
22         this.wage = wage;
23         this.hours = hours;
24      }
25
26      // set wage
27      public void setWage(double wage) {
28         if (wage < 0.0) // validate wage
29            throw new IllegalArgumentException("Hourly wage must be >= 0.0");
30         }
31
32         this.wage = wage;
33      }
34
35      // return wage
36      public double getWage() {return wage;}
37
38      // set hours worked
39      public void setHours(double hours) {
40         if ((hours < 0.0) || (hours > 168.0)) // validate hours
41            throw new IllegalArgumentException(
42               "Hours worked must be >= 0.0 and <= 168.0");
43         }
44
45         this.hours = hours;
46      }
47
48      // return hours worked
49      public double getHours() {return hours;}
50
51      // calculate earnings; override abstract method earnings in Employee
52      @Override                                                          
53      public double earnings() {                                          
54         if (getHours() <= 40) // no overtime                            
55            return getWage() * getHours();                                
56         }                                                                
57         else {                                                          
58            return 40 * getWage() + (getHours() - 40) * getWage() * 1.5;  
59         }                                                                
60      }                                                                  
61
62      // return String representation of HourlyEmployee object            
63      @Override                                                            
64      public String toString() {                                          
65         return String.format("hourly employee: %s%n%s: $%,.2f; %s: %,.2f",
66            super.toString(), "hourly wage", getWage(),                    
67            "hours worked", getHours());                                  
68      }                                                                    
69   }
1   // Fig. 10.7: CommissionEmployee.java
 2   // CommissionEmployee class extends Employee.
 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 sales amount
28      public void setGrossSales(double grossSales) {
29         if (grossSales < 0.0) { // validate
30            throw new IllegalArgumentException("Gross sales must be >= 0.0");
31         }
32
33         this.grossSales = grossSales;
34      }
35
36      // return gross sales amount
37      public double getGrossSales(){return grossSales;}
38
39      // set commission rate
40      public void setCommissionRate(double commissionRate) {
41         if (commissionRate <= 0.0 || commissionRate >= 1.0)  { // validate
42            throw new IllegalArgumentException(
43               "Commission rate must be > 0.0 and < 1.0");
44         }
45
46         this.commissionRate = commissionRate;
47      }
48
49      // return commission rate
50      public double getCommissionRate() {return commissionRate;}
51
52      // calculate earnings; override abstract method earnings in Employee
53      @Override                                                          
54      public double earnings() {                                          
55         return getCommissionRate() * getGrossSales();                    
56      }                                                                  
57
58      // return String representation of CommissionEmployee object
59      @Override                                                  
60      public String toString() {                                  
61         return String.format("%s: %s%n%s: $%,.2f; %s: %.2f",    
62            "commission employee", super.toString(),              
63            "gross sales", getGrossSales(),                      
64            "commission rate", getCommissionRate());              
65      }                                                          
66   }
Fig.10.8 BasePlusCommissionEmployee class extends CommissionEmployee.
 1   // Fig. 10.8: BasePlusCommissionEmployee.java
 2   // BasePlusCommissionEmployee class extends CommissionEmployee.
 3
 4   public class BasePlusCommissionEmployee extends CommissionEmployee {
 5      private double baseSalary; // base salary per week
 6
 7      // constructor
 8      public BasePlusCommissionEmployee(String firstName, String lastName,
 9         String socialSecurityNumber, double grossSales,
10         double commissionRate, double baseSalary) {
11         super(firstName, lastName, socialSecurityNumber,
12            grossSales, commissionRate);
13
14         if (baseSalary < 0.0) { // validate baseSalary
15            throw new IllegalArgumentException("Base salary must be >= 0.0");
16         }
17
18         this.baseSalary = baseSalary;
19      }
20
21      // set base salary
22      public void setBaseSalary(double baseSalary) {
23         if (baseSalary < 0.0) { // validate baseSalary
24            throw new IllegalArgumentException("Base salary must be >= 0.0");
25         }
26
27         this.baseSalary = baseSalary;
28      }
29
30      // return base salary
31      public double getBaseSalary() { return baseSalary;}
32
33      // calculate earnings; override method earnings in CommissionEmployee
34      @Override                                                            
35      public double earnings() {return getBaseSalary() + super.earnings();}
36
37      // return String representation of BasePlusCommissionEmployee object
38      @Override                                                          
39      public String toString() {                                          
40         return String.format("%s %s; %s: $%,.2f",                        
41            "base-salaried", super.toString(),                            
42            "base salary", getBaseSalary());                              
43      }                                                                  
44   }
Fig.10.9 Employee hierarchy test program.
 1   // Fig. 10.9: PayrollSystemTest.java
 2   // Employee hierarchy test program.
 3
 4   public class PayrollSystemTest {
 5      public static void main(String[] args) {
 6         // create subclass objects                                          
 7         SalariedEmployee salariedEmployee =                                
 8            new SalariedEmployee("John", "Smith", "111-11-1111", 800.00);    
 9         HourlyEmployee hourlyEmployee =                                    
10            new HourlyEmployee("Karen", "Price", "222-22-2222", 16.75, 40);  
11         CommissionEmployee commissionEmployee =                            
12            new CommissionEmployee(                                          
13            "Sue", "Jones", "333-33-3333", 10000, .06);                      
14         BasePlusCommissionEmployee basePlusCommissionEmployee =            
15            new BasePlusCommissionEmployee(                                  
16            "Bob", "Lewis", "444-44-4444", 5000, .04, 300);                  
17
18         System.out.println("Employees processed individually:");
19
20         System.out.printf("%n%s%n%s: $%,.2f%n%n",
21            salariedEmployee, "earned", salariedEmployee.earnings());
22         System.out.printf("%s%n%s: $%,.2f%n%n",
23            hourlyEmployee, "earned", hourlyEmployee.earnings());
24         System.out.printf("%s%n%s: $%,.2f%n%n",
25            commissionEmployee, "earned", commissionEmployee.earnings());
26         System.out.printf("%s%n%s: $%,.2f%n%n",
27            basePlusCommissionEmployee,
28            "earned", basePlusCommissionEmployee.earnings());
29
30         // create four-element Employee array
31         Employee[] employees = new Employee[4];  
32
33         // initialize array with Employees          
34         employees[0] = salariedEmployee;            
35         employees[1] = hourlyEmployee;              
36         employees[2] = commissionEmployee;          
37         employees[3] = basePlusCommissionEmployee;  
38
39         System.out.printf("Employees processed polymorphically:%n%n");
40
41         // generically process each element in array employees
42         for (Employee currentEmployee : employees) {
43            System.out.println(currentEmployee); // invokes toString
44
45            // determine whether element is a BasePlusCommissionEmployee
46            if currentEmployee instanceof BasePlusCommissionEmployee {
47               // downcast Employee reference to
48               // BasePlusCommissionEmployee reference
49               BasePlusCommissionEmployee employee =
50                  (BasePlusCommissionEmployee) currentEmployee ;
51
52               employee.setBaseSalary(1.10 * employee.getBaseSalary());
53
54               System.out.printf(
55                  "new base salary with 10%% increase is: $%,.2f%n",
56                  employee.getBaseSalary());
57            }
58
59            System.out.printf(
60               "earned $%,.2f%n%n", currentEmployee.earnings());
61         }
62
63         // get type name of each object in employees array
64         for (int j = 0; j < employees.length; j++) {      
65            System.out.printf("Employee %d is a %s%n", j,  
66               employees[j].getClass().getName());        
67         }                                                
68      }
69   }