Define inheritance and polymorphism

Assignment Help C/C++ Programming
Reference no: EM13764542

Inheritance and Polymorphism

The objective of this programming assignment is to experience the use of inheritance in Java and to see how polymorphism works with inheritance in Java.

The assignment involves writing three classes, plus a test class. The base class is an employee class which contains a couple of attributes common to all employees and a fundamental method to calculate pay. The two derived classes are a commissioned employee that adds payment of a sales commission as part of the pay calculation, and a union employee which adds overtime payment and union dues as part of the pay calculation. The test program will be structured to include a method which accepts a base class reference and demonstrates polymorphic behavior.

The details of the three classes to be implemented are as follows:

1. An Employee contains a name, a department where the employee works, and an hourly rate of pay. An explicit value constructor should be provided to set all three values when an Employee object is created. There should be mutator methods to set the values of the department and the pay rate. There should be one accessor method which returns a string containing the name and the department in which the employee works. Finally, there should be a weekly pay method that takes an integer parameter for the number of hours worked and returns the weekly pay. If the number of hours worked is less than 40 hours, the pay is the number of hours times the rate. If the number of hours worked is 40 or more, the pay is 40 times the rate.

2. The Union Employee inherits from the Employee class. A Union Employee contains a dues variable which holds the amount of dues a Union Employee has withheld from their paycheck each week. An explicit value constructor should be provided to set all three values from the base class along with the dues value. There should be a mutator method provided to set the dues variable. The base class weekly pay method should be overridden because a Union Employee gets 1.5 times the rate for any hours over 40 per week. This method should use the base class method to calculate pay for first 40 hours and then add the overtime amount. Also the weekly pay is reduced by the amount of dues withheld.

3. The Commission Employee inherits from the Employee class. A Commission Employee contains a commission rate and a sales amount variable which are used as part of the pay calculation. An explicit value constructor should be provided to set all 3 values of the base class along with the commission rate variable. There should be mutator methods for the commission rate and the sales amount. The base class weekly pay method should be overridden because the Commission Employee gets the base employee pay plus the commission rate times the sales amount. This method should use the base class weekly pay method to calculate the hourly part of the pay.

4. The test program needs to create a Union Employee object and a Commission Employee object. The test program must contain a display method which takes a base class Employee object reference along with the number of hours worked by the employee. The display method should use the base class method to get the employee name and department info and output that information. The display method should also use the base class method to get the weekly pay info for the employee object and display that information. The test program should pass the Union Employee object and the Commission Employee object to the display method along with the number of hours each employee has worked. It should test the payroll calculation for the number of hours worked to be less than 40, 40, and greater than 40 hours for each employee type. The output seen should demonstrate polymorphic behavior, that is the base class Employee reference to a Union Employee object elicits Union Employee pay calculations, and the base class Employee reference to a Commission Employee elicits Commission Employee payroll calculations.

Reference no: EM13764542

Questions Cloud

How to deal with the question of working capital : how to deal with the question of working capital - use of excess production facilities and building space?
Explain the pretrial process : Create a 6 to 9 slide presentation in which you explain the pretrial process, along with the following associated activities: Pretrial detention and the concept of bail
Building blocks of classes : How can you employer structures and utilize constructors? Explain the role of classes in encapsulating data.
Provide your legal research within your memorandum : Do not forget to provide your legal research within your memorandum. You may use case law to make comparisons, your textbook, and reliable Internet research to provide in-text citations for your work. Do not use Wikipedia
Define inheritance and polymorphism : Inheritance and Polymorphism, The objective of this programming assignment is to experience the use of inheritance in Java and to see how polymorphism works with inheritance in Java.
How corporations and individuals in positions of power : Using the Internet and library, provide at least 2 examples of how corporations and individuals in positions of power and authority have acted unethically either by their actions or inactions
Potential impact on the organization profitability : You have been asked to assess certain risks of an organization and quantify their potential impact on the organization's profitability. As a result of your inquiry, you have determined that the firm is exposed to two primary risks.
Identify current ethical concerns regarding animal shelters : For this project assignment, identify current ethical concerns regarding animal shelters ( no-kill) . You are required to diligently research and find, at a minimum, five concerns that are currently plaguing this industry
Relationship between supply chain and supply - demand model : Discuss the relationship between supply chain and the supply and demand model.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Prepare a program that uses the pthread library

Prepare a C/C++ program that uses the PTHREAD library to create threads and mutexes to synchronize them.

  Write program that takes number show number in power of 3

Write a program that takes a number between -121 and 121 and output that number in the format of power of 3 (1,3,9,27)

  Write a program that inputs two characters

Write a program that inputs two characters from the keyboard and passes them to function packCharacters.

  C is a general-purpose programming language designed as an

c is a general-purpose programming language designed as an improvement to the c programming language. in short the

  Question 1 create an object oriented application with c

question 1 create an object oriented application with c that computes the area of a rectangle and the area and the

  Write a c program that will calculate the gross pay of a

write a c program that will calculate the gross pay of a set of employees.for each employee the program should prompt

  Train traveling in terms of minutes

Write a code for the following C++ problem. We will have a user that will be asked to input the time of a train traveling in terms of minutes and these minutes is a non-negative integer.

  Write program in c++ for cosx and sinx expansion

Write program in c++ for cosx and sinx expansion( for personal inputs are x,number of terms

  Prepare a businesspartner

Prepare a BusinessPartner class that contains a company name, first name and a telephone number.

  Calculate distances and map a route

The GPS navigation system uses the graph and geometric algorithms to calculate distances and map a route. One of the geometric problems is the closest-pair problem. Given a set of points, the closest-pair problem is to find the two points that are..

  Variable of primitive type

What value is stored in ch by the following statement? ch = str.charAt(0); What value is stored in ch by the following statement? ch = str.charAt(10);

  Generate mathematical problems based on the difficulty level

Generate mathematical problems based on the difficulty level selected. You must implement the following five levels of difficulty

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd