SlideShare une entreprise Scribd logo
1  sur  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 !!!!!!!!

Contenu connexe

Plus de ashhadiqbal

Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6Cis 355 ilab 3 of 6
Cis 355 ilab 3 of 6ashhadiqbal
 
Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6Cis 355 ilab 2 of 6
Cis 355 ilab 2 of 6ashhadiqbal
 
Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6Cis 355 ilab 1 of 6
Cis 355 ilab 1 of 6ashhadiqbal
 
Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6Cis 355 ilab 6 of 6
Cis 355 ilab 6 of 6ashhadiqbal
 
Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7Comp 220 ilab 6 of 7
Comp 220 ilab 6 of 7ashhadiqbal
 
Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7Comp 220 ilab 5 of 7
Comp 220 ilab 5 of 7ashhadiqbal
 
Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7Comp 220 ilab 3 of 7
Comp 220 ilab 3 of 7ashhadiqbal
 
Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7Comp 220 ilab 7 of 7
Comp 220 ilab 7 of 7ashhadiqbal
 
CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7CIS/336 ilab 1 of 7
CIS/336 ilab 1 of 7ashhadiqbal
 
CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7CIS/115 ilab 4 of 7
CIS/115 ilab 4 of 7ashhadiqbal
 

Plus 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
 

Dernier

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 ConsultingTechSoup
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 

Dernier (20)

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
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 

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 !!!!!!!!