SlideShare uma empresa Scribd logo
1 de 2
COMP/274 Week 3 - 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 oneaccessor 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.


Take screen shots of the output of the program. Paste the screen shots and your source
code for all your classes into a Word document.


CLICK HERE TO GET THE SOLUTION !!!!!!!!

Mais conteúdo relacionado

Mais de ashhadiqbal

Mais de ashhadiqbal (14)

Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6
 
Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6
 
Ilab 2 of 7
Ilab 2 of 7Ilab 2 of 7
Ilab 2 of 7
 
Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7
 
CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7
 
PRG/421 Week 4
PRG/421 Week 4PRG/421 Week 4
PRG/421 Week 4
 
PRG/421 Week 2
PRG/421 Week 2PRG/421 Week 2
PRG/421 Week 2
 
PRG/421 Week 1
PRG/421 Week 1PRG/421 Week 1
PRG/421 Week 1
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Third Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptxThird Battle of Panipat detailed notes.pptx
Third Battle of Panipat detailed notes.pptx
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 

COMP/274 Week 3

  • 1. COMP/274 Week 3 - 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 oneaccessor 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.
  • 2. 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. Take screen shots of the output of the program. Paste the screen shots and your source code for all your classes into a Word document. CLICK HERE TO GET THE SOLUTION !!!!!!!!