SlideShare une entreprise Scribd logo
1  sur  2
SOLUTIONJUG.COM
CLICK HERE TO GET THE SOLUTION !!!!!
COMP/274 Week 2 - 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 a TaxableWorker
class which contains a couple of attributes and methods common to all workers. The first derived
class is a StateTaxableWorker which adds state tax information to a TaxableWorker. The second
derived class is a LocalTaxableWorker which adds local tax information to a StateTaxableWorker.
The test program will be structured to include a method which accepts a base class reference and
demonstrates polymorphic behavior.
NOTE: None of the first three classes below do any user input or console output! User input and
console output are only done in the test program!
The details of the three classes to be implemented are as follows:
A TaxableWorker contains a name, an hourly pay rate (ie. 12.50/hr), and a federal tax rate (ie.
0.25). An explicit value constructor must be provided to set all three values. There must be mutator
methods to change the values of the pay rate and the tax rate. There must be ONE workerInfo
method that returns a string containing the name, hourly pay rate, and federal tax rate. There must
be a grossPay method that takes the number of hours worked as a parameter and calculates the
gross pay (hours * payRate) and returns that as a double. There must be a taxWithheld method that
takes a gross pay amount as a parameter and calculates the tax withheld (grossPay * taxRate) and
returns that as a double.
The StateTaxableWorker class inherits from the TaxableWorker class. This class adds attributes for
the state name and the state tax rate (ie. 0.05). An explicit value constructor must be provided to
set the three values of the base class plus the values for the state name and state tax rate. A
mutator method must be provided to change the value of the state tax rate. The base class
workerInfo method must be overridden to include all the base class worker information plus the
state name and state tax rate information. The base class taxWithheld method must be overridden
to include the base class tax withheld plus the state tax withheld (gross pay * state tax rate).
The LocalTaxableWorker class inherits from the StateTaxableWorker class. This class adds attributes
for the city name and the city tax rate (ie. 0.025). An explicit value constructor must be provided to
set the three values of the base class plus the two values for the state name and state tax rate plus
the city name and the city tax rate. A mutator method must be provided to change the value of the
city tax rate. The base class workerInfo method must be overridden to include all the state worker
information (which includes base class info) plus the city name and city tax rate information. The
base class taxWithheld method must be overridden to include the state tax withheld (which includes
the base tax withheld) plus the city tax withheld (gross pay * city tax rate).
The test program needs to create a StateTaxableWorker object and a LocalTaxableWorker object.
The test program must contain a display method which takes a base class TaxableWorker object
reference along with the number of hours worked by the worker. The display method should use the
base class workerInfo method to get the name and tax information about the worker and output
that information. The display method should also use the base class grossPay method to get the pay
info for the worker and display that information. Then the display method should use the
taxWithheld method to output the total amount of tax withheld for the worker.
The test program should pass the StateTaxableWorker object and the LocalTaxableWorker object to
the display method along with the number of hours each worker has worked. The output seen
should demonstrate polymorphic behavior, that is the base class TaxableWorker reference to a
StateTaxableWorker object elicits StateTaxableWorker tax information and correct tax withheld, and
the base class TaxableWorker reference to a LocalTaxableWorker object elicits LocalTaxableWorker
tax information and correct tax withheld.
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.
Screenshot 1
CLICK HERE TO GET THE SOLUTION !!!!!

Contenu connexe

En vedette

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

En vedette (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Comp 274 week 2 programming assignment

  • 1. SOLUTIONJUG.COM CLICK HERE TO GET THE SOLUTION !!!!! COMP/274 Week 2 - 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 a TaxableWorker class which contains a couple of attributes and methods common to all workers. The first derived class is a StateTaxableWorker which adds state tax information to a TaxableWorker. The second derived class is a LocalTaxableWorker which adds local tax information to a StateTaxableWorker. The test program will be structured to include a method which accepts a base class reference and demonstrates polymorphic behavior. NOTE: None of the first three classes below do any user input or console output! User input and console output are only done in the test program! The details of the three classes to be implemented are as follows: A TaxableWorker contains a name, an hourly pay rate (ie. 12.50/hr), and a federal tax rate (ie. 0.25). An explicit value constructor must be provided to set all three values. There must be mutator methods to change the values of the pay rate and the tax rate. There must be ONE workerInfo method that returns a string containing the name, hourly pay rate, and federal tax rate. There must be a grossPay method that takes the number of hours worked as a parameter and calculates the gross pay (hours * payRate) and returns that as a double. There must be a taxWithheld method that takes a gross pay amount as a parameter and calculates the tax withheld (grossPay * taxRate) and returns that as a double. The StateTaxableWorker class inherits from the TaxableWorker class. This class adds attributes for the state name and the state tax rate (ie. 0.05). An explicit value constructor must be provided to set the three values of the base class plus the values for the state name and state tax rate. A mutator method must be provided to change the value of the state tax rate. The base class workerInfo method must be overridden to include all the base class worker information plus the state name and state tax rate information. The base class taxWithheld method must be overridden to include the base class tax withheld plus the state tax withheld (gross pay * state tax rate). The LocalTaxableWorker class inherits from the StateTaxableWorker class. This class adds attributes for the city name and the city tax rate (ie. 0.025). An explicit value constructor must be provided to set the three values of the base class plus the two values for the state name and state tax rate plus the city name and the city tax rate. A mutator method must be provided to change the value of the city tax rate. The base class workerInfo method must be overridden to include all the state worker information (which includes base class info) plus the city name and city tax rate information. The
  • 2. base class taxWithheld method must be overridden to include the state tax withheld (which includes the base tax withheld) plus the city tax withheld (gross pay * city tax rate). The test program needs to create a StateTaxableWorker object and a LocalTaxableWorker object. The test program must contain a display method which takes a base class TaxableWorker object reference along with the number of hours worked by the worker. The display method should use the base class workerInfo method to get the name and tax information about the worker and output that information. The display method should also use the base class grossPay method to get the pay info for the worker and display that information. Then the display method should use the taxWithheld method to output the total amount of tax withheld for the worker. The test program should pass the StateTaxableWorker object and the LocalTaxableWorker object to the display method along with the number of hours each worker has worked. The output seen should demonstrate polymorphic behavior, that is the base class TaxableWorker reference to a StateTaxableWorker object elicits StateTaxableWorker tax information and correct tax withheld, and the base class TaxableWorker reference to a LocalTaxableWorker object elicits LocalTaxableWorker tax information and correct tax withheld. 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. Screenshot 1 CLICK HERE TO GET THE SOLUTION !!!!!