message with details. Programmer assignment need seven classes. Classes must complie and read word doc.
message with details. Programmer assignment need seven classes. Classes must complie and read word doc.
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.7Fig.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 };1112 // constructor: confirm proper value for month and day given the year13 public Date(int month, int day, int year) {14 // check if month in range15 if (month <= 0 || month > 12)16 throw new IllegalArgumentException(17 “month (” + month + “) must be 1-12”);18 }1920 // check if day in range for month21 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 }2627 // check for leap year if month is 2 and day is 2928 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 }3334 this.month = month;35 this.day = day;36 this.year = year;3738 System.out.printf(“Date object constructor for date %s%n”, this);39 }4041 // return a String of the form month/day/year42 public String toString() {43 return String.format(“%d/%d/%d”, month, day, year);44 }45 }Fig 10.4Fig.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 // constructor10 public Employee(String firstName, String lastName,11 String socialSecurityNumber) {12 this.firstName = firstName;13 this.lastName = lastName;14 this.socialSecurityNumber = socialSecurityNumber;15 }1617 // return first name18 public String getFirstName() {return firstName;}1920 // return last name21 public String getLastName() {return lastName;}2223 // return social security number24 public String getSocialSecurityNumber() {return socialSecurityNumber;}2526 // return String representation of Employee object27 @Override28 public String toString() {29 return String.format(“%s %s%nsocial security number: %s”,30 getFirstName(), getLastName(), getSocialSecurityNumber());31 }3233 // abstract method must be overridden by concrete subclasses34 public abstract double earnings(); // no implementation here35 }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);1112 if (weeklySalary < 0.0) {13 throw new IllegalArgumentException(14 "Weekly salary must be >= 0.0″);15 }1617 this.weeklySalary = weeklySalary;18 }1920 // set salary21 public void setWeeklySalary(double weeklySalary) {22 if (weeklySalary < 0.0) {23 throw new IllegalArgumentException(24 "Weekly salary must be >= 0.0″);25 }2627 this.weeklySalary = weeklySalary;28 }2930 // return salary31 public double getWeeklySalary(){return weeklySalary;}3233 // calculate earnings; override abstract method earnings in Employee34 @Override 35 public double earnings() {return getWeeklySalary();} 3637 // 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);1213 if (wage < 0.0) // validate wage14 throw new IllegalArgumentException("Hourly wage must be >= 0.0″);15 }1617 if ((hours < 0.0) || (hours > 168.0)) { // validate hours18 throw new IllegalArgumentException(19 “Hours worked must be >= 0.0 and <= 168.0");20 }2122 this.wage = wage;23 this.hours = hours;24 }2526 // set wage27 public void setWage(double wage) {28 if (wage < 0.0) // validate wage29 throw new IllegalArgumentException("Hourly wage must be >= 0.0″);30 }3132 this.wage = wage;33 }3435 // return wage36 public double getWage() {return wage;}3738 // set hours worked39 public void setHours(double hours) {40 if ((hours < 0.0) || (hours > 168.0)) // validate hours41 throw new IllegalArgumentException(42 “Hours worked must be >= 0.0 and <= 168.0");43 }4445 this.hours = hours;46 }4748 // return hours worked49 public double getHours() {return hours;}5051 // calculate earnings; override abstract method earnings in Employee52 @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 } 6162 // 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 // constructor9 public CommissionEmployee(String firstName, String lastName,10 String socialSecurityNumber, double grossSales,11 double commissionRate) {12 super(firstName, lastName, socialSecurityNumber);1314 if (commissionRate <= 0.0 || commissionRate >= 1.0) // validate15 throw new IllegalArgumentException(16 “Commission rate must be > 0.0 and < 1.0");17 }1819 if (grossSales < 0.0) { // validate20 throw new IllegalArgumentException("Gross sales must be >= 0.0″);21 }2223 this.grossSales = grossSales;24 this.commissionRate = commissionRate;25 }2627 // set gross sales amount28 public void setGrossSales(double grossSales) {29 if (grossSales < 0.0) { // validate30 throw new IllegalArgumentException("Gross sales must be >= 0.0″);31 }3233 this.grossSales = grossSales;34 }3536 // return gross sales amount37 public double getGrossSales(){return grossSales;}3839 // set commission rate40 public void setCommissionRate(double commissionRate) {41 if (commissionRate <= 0.0 || commissionRate >= 1.0) { // validate42 throw new IllegalArgumentException(43 “Commission rate must be > 0.0 and < 1.0");44 }4546 this.commissionRate = commissionRate;47 }4849 // return commission rate50 public double getCommissionRate() {return commissionRate;}5152 // calculate earnings; override abstract method earnings in Employee53 @Override 54 public double earnings() { 55 return getCommissionRate() * getGrossSales(); 56 } 5758 // return String representation of CommissionEmployee object59 @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);1314 if (baseSalary < 0.0) { // validate baseSalary15 throw new IllegalArgumentException("Base salary must be >= 0.0″);16 }1718 this.baseSalary = baseSalary;19 }2021 // set base salary22 public void setBaseSalary(double baseSalary) {23 if (baseSalary < 0.0) { // validate baseSalary24 throw new IllegalArgumentException("Base salary must be >= 0.0″);25 }2627 this.baseSalary = baseSalary;28 }2930 // return base salary31 public double getBaseSalary() { return baseSalary;}3233 // calculate earnings; override method earnings in CommissionEmployee34 @Override 35 public double earnings() {return getBaseSalary() + super.earnings();}3637 // return String representation of BasePlusCommissionEmployee object38 @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); 1718 System.out.println(“Employees processed individually:”);1920 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());2930 // create four-element Employee array31 Employee[] employees = new Employee[4]; 3233 // initialize array with Employees 34 employees[0] = salariedEmployee; 35 employees[1] = hourlyEmployee; 36 employees[2] = commissionEmployee; 37 employees[3] = basePlusCommissionEmployee; 3839 System.out.printf(“Employees processed polymorphically:%n%n”);4041 // generically process each element in array employees42 for (Employee currentEmployee : employees) {43 System.out.println(currentEmployee); // invokes toString4445 // determine whether element is a BasePlusCommissionEmployee46 if currentEmployee instanceof BasePlusCommissionEmployee {47 // downcast Employee reference to48 // BasePlusCommissionEmployee reference49 BasePlusCommissionEmployee employee =50 (BasePlusCommissionEmployee) currentEmployee ;5152 employee.setBaseSalary(1.10 * employee.getBaseSalary());5354 System.out.printf(55 “new base salary with 10%% increase is: $%,.2f%n”,56 employee.getBaseSalary());57 }5859 System.out.printf(60 “earned $%,.2f%n%n”, currentEmployee.earnings());61 }6263 // get type name of each object in employees array64 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 }
Why Choose Us
- 100% non-plagiarized Papers
- 24/7 /365 Service Available
- Affordable Prices
- Any Paper, Urgency, and Subject
- Will complete your papers in 6 hours
- On-time Delivery
- Money-back and Privacy guarantees
- Unlimited Amendments upon request
- Satisfaction guarantee
How it Works
- Click on the “Place Order” tab at the top menu or “Order Now” icon at the bottom and a new page will appear with an order form to be filled.
- Fill in your paper’s requirements in the "PAPER DETAILS" section.
- Fill in your paper’s academic level, deadline, and the required number of pages from the drop-down menus.
- Click “CREATE ACCOUNT & SIGN IN” to enter your registration details and get an account with us for record-keeping and then, click on “PROCEED TO CHECKOUT” at the bottom of the page.
- From there, the payment sections will show, follow the guided payment process and your order will be available for our writing team to work on it.