Quick Index

Objectives



Steps



Problem Statement


Concept


Code up a tax calculator.

The calculator should be able to compute taxes for any "taxable" object.

The model solution consists of a TaxCalculator and a Taxable type. Note that "Taxable" is a Java interface meaning it is an "idea". Thus, object users will have to replace it with "real" objects for use.

TaxCalculator


I am a simple calculator that calculates the tax for a Taxable type.

Note that my element must be a Taxable object type. I do not care if my ivar "element" is a car, house, etc. As long as it's a Taxable type, I'm happy.

I use OO encapsulation. I hide the unpleasant details of money math (rounding errors).

Taxable


I am the "idea" for something taxable.

Hint: Java interface = idea.

Note that we do not need to declare interface methods public. They are public by default.

Coding requirements:







































































































Hints


Write test code as you code this model.





































































































Solution


Here is code with explanations:






































































































Test Code


Testing Problem Statement


Also reference the Association test write-up as needed.

Write code to test the model. If you get stumped, look at test code solution.

Test Code Solution


First, try to write test code yourself. Then review and compare the following for possible ideas.

Some helper class code to use on the tests:


The test code:


Here is support code that is needed for the test code.

Note that this support code is just one example of a minimal testing framework. Feel free to build your own.