Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify so that all employees can be given different vacation options depending on their claissification. Modify the driver class to demonstrate this capability. //******************************************************************** //

Modify so that all employees can be given different vacation options depending on their claissification. Modify the driver class to demonstrate this capability.

//******************************************************************** // Firm.java // // Demonstrates polymorphism via inheritance. //********************************************************************

public class Firm { //----------------------------------------------------------------- // Creates a staff of employees for a firm and pays them. //-----------------------------------------------------------------

public static void main(String[] args) { Staff personnel = new Staff(); personnel.payday(); } }

//******************************************************************** // Staff.java // Tulsi Kuber // // Project Assignment #4 // Update for Staff class to add two additional commissioned employees to the // staffList to test your class. // Represents the personnel staff of a particular business. //********************************************************************

public class Staff { StaffMember[] staffList;

//----------------------------------------------------------------- // Sets up the list of staff members. //----------------------------------------------------------------- public Staff () { staffList = new StaffMember[8];

staffList[0] = new Executive ("Sam", "123 Main Line", "555-0469", "123-45-6789", 2423.07);

staffList[1] = new Employee ("Carla", "456 Off Line", "555-0101", "987-65-4321", 1246.15);

staffList[2] = new Employee ("Woody", "789 Off Rocker", "555-0000", "010-20-3040", 1169.23);

staffList[3] = new Hourly ("Diane", "678 Fifth Ave.", "555-0690", "958-47-3625", 10.55);

staffList[4] = new Volunteer ("Norm", "987 Suds Blvd.", "555-8374");

staffList[5] = new Volunteer ("Cliff", "321 Duds Lane", "555-7282");

// 1st additional commissioned employee // earns $6.25 hourly and 20% commission staffList[6] = new Commission("Chelsea", "382 Leland Street", "228-9421", "128-38-4869", 6.25, 0.2);

// 2nd additional commissioned employee // earns $9.75 hourly and 15% commission staffList[7] = new Commission("Cooper", "235 6th Ave.", "830-7535", "201-55-6009", 9.75, 0.15);

((Executive)staffList[0]).awardBonus (500.00);

((Hourly)staffList[3]).addHours (40); ((Commission)staffList[6]).addHours(35);// Chelsea worked 35 hours ((Commission)staffList[6]).addSales(400);// Chelsea total sales at $400 ((Commission)staffList[7]).addHours(40);// Cooper worked 40 hours ((Commission)staffList[7]).addSales(950);// Cooper total sales at $950 }

//----------------------------------------------------------------- // Pays all staff members. //----------------------------------------------------------------- public void payday () { double amount;

for (int count=0; count < staffList.length; count++) { System.out.println (staffList[count]);

amount = staffList[count].pay(); // polymorphic

if (amount == 0.0) System.out.println ("Thanks!"); else System.out.println ("Paid: " + amount);

System.out.println ("-----------------------------------"); } }

}

//******************************************************************** // StaffMember.java // // Represents a generic staff member. //******************************************************************** abstract public class StaffMember { protected String name; protected String address; protected String phone; //----------------------------------------------------------------- // Constructor: Sets up this staff member using the specified // information. //----------------------------------------------------------------- public StaffMember(String eName, String eAddress, String ePhone) { name = eName; address = eAddress; phone = ePhone; } //----------------------------------------------------------------- // Returns a string including the basic employee information. //----------------------------------------------------------------- public String toString() { String result = "Name: " + name + " "; result += "Address: " + address + " "; result += "Phone: " + phone; return result; } //----------------------------------------------------------------- // Derived classes must define the pay method for each type of // employee. //----------------------------------------------------------------- public abstract double pay(); }

//******************************************************************** // Volunteer.java // // Represents a staff member that works as a volunteer. //******************************************************************** public class Volunteer extends StaffMember { //----------------------------------------------------------------- // Constructor: Sets up this volunteer using the specified // information. //----------------------------------------------------------------- public Volunteer(String eName, String eAddress, String ePhone) { super(eName, eAddress, ePhone); } //----------------------------------------------------------------- // Returns a zero pay value for this volunteer. //----------------------------------------------------------------- public double pay() { return 0.0; } }

//******************************************************************** // Employee.java // // Represents a general paid employee. //******************************************************************** public class Employee extends StaffMember { protected String socialSecurityNumber; protected double payRate; //----------------------------------------------------------------- // Constructor: Sets up this employee with the specified // information. //----------------------------------------------------------------- public Employee(String eName, String eAddress, String ePhone, String socSecNumber, double rate) { super(eName, eAddress, ePhone); socialSecurityNumber = socSecNumber; payRate = rate;

} //----------------------------------------------------------------- // Returns information about an employee as a string. //----------------------------------------------------------------- public String toString() { String result = super.toString(); result += " Social Security Number: " + socialSecurityNumber; return result; } //----------------------------------------------------------------- // Returns the pay rate for this employee. //----------------------------------------------------------------- public double pay() { return payRate; } }

//******************************************************************** // Executive.java // // Represents an executive staff member, who can earn a bonus. //******************************************************************** public class Executive extends Employee { private double bonus; //----------------------------------------------------------------- // Constructor: Sets up this executive with the specified // information. //----------------------------------------------------------------- public Executive(String eName, String eAddress, String ePhone, String socSecNumber, double rate) { super(eName, eAddress, ePhone, socSecNumber, rate); bonus = 0; // bonus has yet to be awarded } //----------------------------------------------------------------- // Awards the specified bonus to this executive. //----------------------------------------------------------------- public void awardBonus(double execBonus) { bonus = execBonus; } //----------------------------------------------------------------- // Computes and returns the pay for an executive, which is the // regular employee payment plus a one-time bonus. //----------------------------------------------------------------- public double pay() { double payment = super.pay() + bonus; bonus = 0; return payment; } }

//******************************************************************** // Hourly.java // // Represents an employee that gets paid by the hour. //******************************************************************** public class Hourly extends Employee { private int hoursWorked; //----------------------------------------------------------------- // Constructor: Sets up this hourly employee using the specified // information. //----------------------------------------------------------------- public Hourly(String eName, String eAddress, String ePhone, String socSecNumber, double rate) { super(eName, eAddress, ePhone, socSecNumber, rate); hoursWorked = 0; } //----------------------------------------------------------------- // Adds the specified number of hours to this employee's // accumulated hours. //----------------------------------------------------------------- public void addHours(int moreHours) { hoursWorked += moreHours; } //----------------------------------------------------------------- // Computes and returns the pay for this hourly employee. //----------------------------------------------------------------- public double pay() { double payment = payRate * hoursWorked; hoursWorked = 0; return payment; } }

//******************************************************************** // Commission.java // Tulsi Kuber // // Project Assignment #4 // Add one more employee type to the class hierarchy in the Firm example in // Module 10. Write a class named Commission that extends the Hourly class in // the Firm program. // Represents an employee that is paid hourly, as well as commission. //******************************************************************** public class Commission extends Hourly { // instance variables double totalSalesMade; double commissionRate; //----------------------------------------------------------------- // Sets up this commission employee using the specified information. //----------------------------------------------------------------- public Commission (String eName, String eAddress, String ePhone, String socSecNumber, double rate, double cmsnRate) { super (eName, eAddress, ePhone, socSecNumber, rate); commissionRate = cmsnRate; } //----------------------------------------------------------------- // Adds the specified amount of sales to this employee's // accumulated totalSales. //----------------------------------------------------------------- public void addSales (double totalSales) { totalSalesMade += totalSales; } //----------------------------------------------------------------- // Computes and returns the pay for a commission employee, which is the // hourly employee payment plus the commission. //----------------------------------------------------------------- public double pay() { double payment = super.pay() + totalSalesMade * commissionRate;

totalSalesMade = 0;

return payment; } //----------------------------------------------------------------- // Returns information about this commissioned employee as a string. //----------------------------------------------------------------- public String toString() { String result = super.toString();

result += " Total Sales: " + totalSalesMade;

return result; } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions