Question: ***code in java Steps for Doing the Assignment Below are the steps for doing the assignment (For implementation details see the Implementation section): 1.Create classes

***code in java

Steps for Doing the Assignment

Below are the steps for doing the assignment (For implementation details see the Implementation section):

1.Create classes Worker, Manager and Executive

2.Create an abstract class Employee containing an abstract method

3.Make the classes Worker, Manager and Executive as subclasses of the class Employee.

4.Create three Worker objects, two Manager objects and one Executive object

5.Create an array of type Employee of size 6.

6.Store in it references of Worker, Manager and Executive objects.

(This is allowed because objects of type Worker, Manager and Executives are also of type Employee because Employee is their parent class and they inherit all its characteristics).

7.In a For loop, call the method on different objects stored in array to compute their bonus as below.

for (int i=0; i<6; i++) {

double bonus=emp [i].computeBonus( ); //polymorphic call

}

Implementation

Create the following classes:

class Employee

Create an abstract class Employee that includes the following:

Two fields, String name and double salary, for holding employee name and salary.

A constructor for initializing name and salary.

Accessor methods, getName ( ) and getSalary ( ) for returning name and salary respectively.

An abstract method computeBonus ( ) for computing and returning the bonus such as shown below. (Do not provide a body for this method. The child classes will provide their individual implementation of this method.)

public abstract double computeBonus ( );

class Worker

Create a class Worker that extends Employee and provides the following:

A field pctBonus for specifying the salary percentage value for the bonus.

A constructor to initialize name, salary and pctBonus.

An accessor method getPctBonus for returning pctBonus value.

A method computeBonus for returning the bonus computed. (Provide a body for this method).

The method computeBonus will compute the bonus as follows:

bonus = salary * pctBonus

class Manager

Create a class Manager that extends Employee and provides the following:

A field pctBonus for specifying the salary percentage value for the bonus.

A field travelExpense for specifying travel expenses assigned.

A constructor to initialize name, salary, pctBonus, and travelExpense.

An accessor method getPctBonus for returning pctBonus value.

An accessor method getTravelExpense for returning travelExpense.

A method computeBonus for returning the bonus computed. (Provide a body for this method).

The method computeBonus will compute the bonus as follows:

bonus = (salary * pctBonus) + 500.00

class Executive

Create a class Executive that extends Employee and provides the following:

A field pctBonus for specifying the percentage value for the bonus.

A field travelExpense for specifying travel expenses available.

A field optionsCount for specifying the number of stock options awarded.

A constructor to initialize name, salary, pctBonus, travelExpense, and optionsCount.

An accessor method getPctBonus for returning pctBonus value.

An accessor method getTravelExpense for returning travelExpense.

An accessor method getOptionsCount for returning optionsCount.

A method computeBonus for returning the bonus computed. (Provide a body for this method).

The method computeBonus will compute the bonus as follows:

bonus = (salary * pctBonus) + 1000.00

class TestEmployee

Create a class TestEmployee containing the main method. The method main will do the following:

Prompt the user to enter the number of workers, say nw.

Prompt the user to enter the number of managers, say nm.

Prompt the user to enter the number of executives, say ne.

Compute the total number of employee (say n) as below:

n = nw + nm + ne

Create an array of n Employee references. (The objects stored will be created in the subsequent steps).

Create nw Worker objects. Do this by setting up an nw count loop. In each pass through the loop, do the following:

Ask the user to enter data for one worker.

Create a Worker object and initialize it with data provided by the user.

Store the Worker object reference in the array of Employee references created earlier at the appropriate location in the Employee array.

Create nm Manager objects. Do this by setting up an nm count loop.

In each pass through the loop, do the following:

Ask the user to enter data for one manager.

Create a Manager object and initialize it with data provided by the user.

Store the Manager object reference in the array of Employee references created earlier.(Store the Manager references in the array elements following where Worker references were stored.)

Create ne Executive objects. Do this by setting up an ne count loop.

In each pass through the loop, do the following:

Ask the user to enter data for one executive.

Create an Executive object and initialize it with data provided by the user.

Store the Executive object reference in the array of Employee references created earlier.

(Store the Executive references in the array elements following where Manager references were stored).

Using a For loop, call computeBonus and getter methods of the objects in the array to produce the required output. See Testing section for output. (See Sample Code section for details.)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!