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

  Smallest sequence of numbers in the array

Write a function called sum_smallest_sequence() that accepts an array of  signed  integers and the  number  of items in the array as arguments, and returns the sum of the smallest sequence of numbers in the array.

  Create a program for a company named retail-martprompt the

create a program for a company named retail-martprompt the user to enter an item name one word only a quantity and a

  C program to compute parking fare for customers

Write C program to compute parking fare for customers who park their cars in parking lot when following information is provided: A character showing type of vehicle: C for car, B for bus and T for truck

  Write a program that calculates an employees wage for a

write a program that calculates an employees wage for a week. an employees wage is calculated as followsi if the number

  Create a program that draws a two-dimensional house

Create a program that draws a two-dimensional house seen from the front, the way a child would see it: with a door, two windows, and a roof with a chimney

  What do the loops print

What do the following loops print? Work out the answer by tracing the code, not by using the computer. a. int s = 1; for (int n = 1; n

  Implement a function named sort

Write a function named sort that takes three integer parameters by reference.The function should rearrange the parameter values so that the first parameter gets set to the smallest value

  Use a define statement to create a constant

Follow these specifications: Use a define statement to create a constant that will hold your student number. You should have separate string variables for your first and last name; name these first_name and last_name.

  Prepare a program that prints the multiplication table

Prepare a program that prints the multiplication table for numbers 1 to 9. The program should include two nested loops and compute the products and print them

  Converts the temperature f in farenheit to c in celsius

Write a program that converts the temperature F in Farenheit to C in Celsius using C = (F-32)*5/9. For ease of programming you can display the result in fractions.

  Program to tell you how many months it will take to pay off

write a program to tell you how many months it will take to pay off any loan, as well as the total amount of interest paid over the life of the loan.

  Calculate the balance by adding deposits

Display the new balance in a ReadOnly text box or a label. Calculate the balance by adding deposits and subtracting service charges and checks. Include buttons for Calculate, Clear, and Exit.

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