Your SlideShare is downloading. ×
Comp 274 week 2 programming assignment
Comp 274 week 2 programming assignment
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Comp 274 week 2 programming assignment

58

Published on

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

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
58
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
1
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. SOLUTIONJUG.COMCLICK HERE TO GET THE SOLUTION !!!!!COMP/274 Week 2 - Inheritance and PolymorphismThe objective of this programming assignment is to experience the use of inheritance in Java and tosee how polymorphism works with inheritance in Java.The assignment involves writing three classes, plus a test class. The base class is a TaxableWorkerclass which contains a couple of attributes and methods common to all workers. The first derivedclass is a StateTaxableWorker which adds state tax information to a TaxableWorker. The secondderived 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 anddemonstrates polymorphic behavior.NOTE: None of the first three classes below do any user input or console output! User input andconsole 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 mutatormethods to change the values of the pay rate and the tax rate. There must be ONE workerInfomethod that returns a string containing the name, hourly pay rate, and federal tax rate. There mustbe a grossPay method that takes the number of hours worked as a parameter and calculates thegross pay (hours * payRate) and returns that as a double. There must be a taxWithheld method thattakes a gross pay amount as a parameter and calculates the tax withheld (grossPay * taxRate) andreturns that as a double.The StateTaxableWorker class inherits from the TaxableWorker class. This class adds attributes forthe state name and the state tax rate (ie. 0.05). An explicit value constructor must be provided toset the three values of the base class plus the values for the state name and state tax rate. Amutator method must be provided to change the value of the state tax rate. The base classworkerInfo method must be overridden to include all the base class worker information plus thestate name and state tax rate information. The base class taxWithheld method must be overriddento 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 attributesfor the city name and the city tax rate (ie. 0.025). An explicit value constructor must be provided toset the three values of the base class plus the two values for the state name and state tax rate plusthe city name and the city tax rate. A mutator method must be provided to change the value of thecity tax rate. The base class workerInfo method must be overridden to include all the state workerinformation (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 includesthe 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 objectreference along with the number of hours worked by the worker. The display method should use thebase class workerInfo method to get the name and tax information about the worker and outputthat information. The display method should also use the base class grossPay method to get the payinfo for the worker and display that information. Then the display method should use thetaxWithheld method to output the total amount of tax withheld for the worker.The test program should pass the StateTaxableWorker object and the LocalTaxableWorker object tothe display method along with the number of hours each worker has worked. The output seenshould demonstrate polymorphic behavior, that is the base class TaxableWorker reference to aStateTaxableWorker object elicits StateTaxableWorker tax information and correct tax withheld, andthe base class TaxableWorker reference to a LocalTaxableWorker object elicits LocalTaxableWorkertax information and correct tax withheld.Take screen shots of the output of the program. Paste the screen shots and your source code for allyour classes into a Word document.Screenshot 1CLICK HERE TO GET THE SOLUTION !!!!!

×