Question

Java Description Write a program to compute bonuses earned this year by employees in an organization....

Java

Description

Write a program to compute bonuses earned this year by employees in an organization. There are three types of employees: workers, managers and executives. Each type of employee is represented by a class. The classes are named Worker, Manager and Executive and are described below in the implementation section.

You are to compute and display bonuses for all the employees in the organization using a single polymorphic loop. This will be done by creating an abstract class Employee and making the classes Worker, Manager and Executive as subclasses of the class Employee. This will allow for creating an array of Employee references and storing in it references of Worker, Manager and Executive objects. (This can be done because objects of classes, Worker, Manager and Executives are also of type Employee as Employee is their parent class and they inherit all its characteristics).

Implementation

Create the following classes:

class Employee

Create an abstract class Employee that includes the following:

Two fields, name and 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. (Do not provide a body for this method).

class Worker

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

A field pctBonus for specifying the 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 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 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).

·                   Find the total bonus amount paid to each employee.

·                   Do this by calling the function computeBonus( ) of each object

·                   using a polymorphic call within a single polymorphic loop as shown below.

In the code below, employee is an array of Employee references containing objects of various Employee subclasses (Worker, Manager, Executive).

String name;

double salary, pctBonus, bonus, travelExpense;

int optionsCount;

for (int i=0; i < employee.length; i++)

{

//get name and salary

//To access target object methods that are defined in class Employee, we don’t need type casting.

name = employee[i].getName ( );

salary = employee[i].getSalary ( );

//call computeBonus using polymorphic call

//Since computeBonus is declared in Employee class, we don’t need type casting.

bonus = employee [i].computeBonus ( );

//use name, salary, bonus, pctBonus returned above towards building the summary report.

String out, outW=””, outM=””, outE=””;

//To access target object methods that are not defined in class Employee, we use down casting.

//Downcasting (Widening) should be done within an if statement using instanceof

//Since getPctBonus method is not present in class Employee, it is accessed via down casting.

//Similarly getTravelExpense, and getOptionsCount are accessed via downcasting.

//The instanceof clause is used below to ensure a safe down casting (widening).

if (employee[i] instanceof Worker){

pctBonus = ( (Worker) employee[i] ).getPctBonus ( );

//accumulate Worker output in outW

outW = outW + “Name:” + name + “\n”;

//add other values in outW

}

else if (employee[i] instanceof Manager) {

pctBonus = ( (Manager) employee[I] ).getPctBonus ( );

travelExpense = ( (Manager) employee[I] ).getTravelExpense ( );

//accumulate Manager output in outM

outM = outM + “Name:” + name + “\n”;

//add other values in outM

        }

else if (employee[i] instanceof Executive) {

pctBonus = ( (Executive) employee[I] ).getPctBonus ( );

travelExpense = ( (Executive) employee[I] ).getTravelExpense ( );

optionsCount = ( (Executive) employee[I] ).getOptionsCount ( );

//accumulate Executive output in outE

outE = outE + “Name:” + name + “\n”;

//add other values in outE

        }

}

//After getting out of the loop

out = outW + outM + outE:

//display out

JOPtionPane.showMessageDialog(null, out);

Testing

Use the following test data.

In the data below, there are 3 workers, 2 managers and 1 executive.

The first employee is John Adam and has a yearly salary of $60000.00 and is paid 5% yearly bonus.

Enter Number of Workers:

3

Enter Number of Managers:

2

Enter Number of Executives:

1

Enter a worker data:

John Adam, 60000, .05

Enter a worker data:

Rick Smith, 65000, .05

Enter a worker data:

Raymond Woo, 70000, .05

Enter a manager data:

Ray Bartlett, 80000, .10, 5000

Enter a manager data:

Mary Russell, 85000, .10, 5000

Enter an executive data:

Andy Wong, 100000, .15, 10000, 500

Output

The output may appear as below:

Name: John Adam

Salary: $ 60000.00

PercentBonus: .05

Total Bonus: $ 3000.00

Name:: Rick Smith

Yearly Salary: $ 65000.00

PercentBonus: .05

Total Bonus: $ 3250.00

Name: Raymond Woo

Yearly Salary: $ 70000.00

PercentBonus: .05

Total Bonus: $ 3500.00

Name: Ray Bartlet

Yearly Salary: $ 80000.00

PercentBonus: .10

Total Bonus: $ 8500.00

Travel Expense: $ 5000.00

Name: Mary Russel

Yearly Salary: $ 85000.00

PercentBonus: .10

Total Bonus: $ 9000.00

Travel Expense: $ 5000.00

Name: Andy Wong

Yearly Salary: $ 100000.00

PercentBonus: .15

Total Bonus: $ 16000.00

Travel Expense: $ 10000.00

Options Count: 500

0 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 10 more requests to produce the answer.

0 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
Java Description Write a program to compute bonuses earned this year by employees in an organization....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • create java application with the following specifications: -create an employee class with the following attibutes: name...

    create java application with the following specifications: -create an employee class with the following attibutes: name and salary -add constuctor with arguments to initialize the attributes to valid values -write corresponding get and set methods for the attributes -add a method in Employee called verify() that returns true/false and validates that the salary falls in range1,000.00-99,999.99 Add a test application class to allow the user to enter employee information and display output: -using input(either scanner or jOption), allow user to...

  • I need to write a Java program. Declare and initialize an ArrayList of type Employee. In...

    I need to write a Java program. Declare and initialize an ArrayList of type Employee. In a while loop, keep initializing objects of type Employee, storing them in the array, and allow the user to enter ID, salary, and leaveDays of the each employee one by one and in one line. Once the user entered a -1, stop initializing new employees, and print "You entered [actual length of array] employees. Thank you!" Create a FOR loop that goes through every...

  • Create the Python code for a program adhering to the following specifications. Write an Employee class...

    Create the Python code for a program adhering to the following specifications. Write an Employee class that keeps data attributes for the following pieces of information: - Employee Name (a string) - Employee Number (a string) Make sure to create all the accessor, mutator, and __str__ methods for the object. Next, write a class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: - Shift number (an integer,...

  • DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...

    DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to be DataSetEmployee. DataSetEmployee should extend ArrayList<Employee> and have no instance variables. You'll have to decide what replaces the getPages concept for getMax/getMin. As a hint, what method of Employee returns a numeric value? Make a package com.acme.midmanager. This package should contain the Manager class. Make a package com.acme.personnel. This package should contain the DataSetEmployee class. Make a package com.acme.topmanagement. This package should contain the...

  • ASAP Please. Python Program Description Create an object-oriented program that allows you to enter data for...

    ASAP Please. Python Program Description Create an object-oriented program that allows you to enter data for employees. Specifications Create an abstract Employee class that provides private attributes for the first name, last name, email address, and social security number. This class should provide functions that set and return the employee’s first name, last name, email address, and social security number. This class has a function: get_net_income which returns 0. Create a Manager class that inherits the Employee class. This class...

  • Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to...

    Status Topic Interfaces Description Video Scene Problem Consider a video scene in which we want to display several different types (classes) of objects. Let's say, we want to display three objects of type Deer, two objects of type Tree and one object of type Hill. Each of them contains a method called display. We would like to store their object references in a single array and then call their method display one by one in a loop. However, in Java,...

  • This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description:...

    This is for Java Programming Please use comments Customer and Employee data (15 pts) Problem Description: Write a program that uses inheritance features of object-oriented programming, including method overriding and polymorphism. Console Welcome to the Person Tester application Create customer or employee? (c/e): c Enter first name: Frank Enter last name: Jones Enter email address: frank44@ hot mail. com Customer number: M10293 You entered: Name: Frank Jones Email: frank44@hot mail . com Customer number: M10293 Continue? (y/n): y Create customer...

  • In Java Problem Description/Purpose:  Write a program that will compute and display the final score...

    In Java Problem Description/Purpose:  Write a program that will compute and display the final score of two teams in a baseball game. The number of innings in a baseball game is 9.    Your program should read the name of the teams. While the user does not enter the word done for the first team name, your program should read the second team name and then read the number of runs for each Inning for each team, calculate the...

  • In C++, Step 1: Implement the Student Class and write a simple main() driver program to...

    In C++, Step 1: Implement the Student Class and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object. The defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file. Student class - The name of the class should be Student. -...

  • *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented...

    *Python* INTRODUCTION: The goal of this programming assignment is to enable the student to practice object-oriented programming using classes to create objects. PROBLEM DEFINITION: Write a class named Employee that holds the following data about an employee in attributes: name, IDnumber, department, jobTitle The class should have 8 methods as follows:  For each attribute, there should be a method that takes a parameter to be assigned to the attribute. This is known as a mutator method.  For each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT