Date Assigned: Wednesday, March 9, 2005
Due Date: Wednesday, March 16, 2005, before the beginning of your lab section.
Goals: to learn how to use inheritance to design an application with derived classes.
Points: This assignment is worth a total of 20 points. No late assignments will be accepted, but credit will be given for partially completed assignments turned in on time.
Assignment: It that time of year when everyone thinks about income taxes. Write an application that creates models of checking and savings accounts for a user, balances those accounts, and then computes and pays the user’s income taxes based upon annual income. For this application, the tax code will be simplified to require everyone to pay a flat 15% of income to the IRS. Follow the steps below to create and balance a user’s accounts and then pay the user’s taxes:
1. Write an application TaxApp. Prompt the user to provide information required, such as the user’s name, annual income, starting checking account balance, and the interest rate on the user’s savings account. Enter no more than 50000.00 for an income. Generously set the user’s savings account to a balance of 10000.00. The application should print out to the screen the return values of the various toString methods. For this lab, it is not necessary to format the output with two decimal places, although there are Java library methods to format decimals or currency.
2. Design a superclass Account
that can be extended to create derived checking and savings subclasses. All accounts should have the following
characteristics:
a.
A field to store the balance of the account, which should be at least
$100.00 at all times (Do not deduct a check from a checking account if it
causes it to fall below this amount.)
b.
A method to deposit funds into the account
c.
A method to determine if sufficient funds exist to withdraw them from an
account (define method as type boolean)
d.
A method to withdraw funds from the account, if sufficient funds exist
e.
Appropriate accessor and toString
methods to retrieve and return values as needed
3. Apply inheritance
to define a checking subclass. Checking
accounts allow 5 free transactions per month, which will be defined as a check
withdrawal or a deposit. Starting with
the 6th transaction, $1.50 will be charged for each additional
transaction. Because of this rule, it will be necessary to override both the
deposit method and the withdrawal method of the superclass
in order to provide a counter for incrementing transactions.
4. Instantiate a checking account object, given the initial amount provided by the user. Balance the user’s checking account by deducting all of the checks, one at a time, listed in the file checks.txt. Deduct transaction fees from the checking account if the number of checks is greater than 5.
5. Apply inheritance to define a savings subclass. Savings accounts pay interest at the rate provided by the user. Write a method computing the interest for the specified balance in the savings account and adding the interest to the account. Assume that the interest you add is for one month, so the annual rate will have to be divided by 12.
6. Instantiate a
savings account object, given the interest rate
provided by the user. Compute and add
the interest for one month to the savings account.
7. Design a
separate class TaxPayment
which computes the taxes due for a user based upon income. This class should have also a method payTax which
withdraws the tax amount due from the checking account if there are sufficient
funds (do not forget to leave at least $100 in the account). This method should have a checking account
object and a savings account object as parameters. If there are not sufficient funds in the
checking account, the method should transfer the additional money required to
pay the taxes from the savings account to the checking account, and then
withdraw the tax amount from the checking account. (Do not charge a transaction fee for any
transfer of funds or for the tax check.)
8. Instantiate a
taxpayment object, supplying the user’s name
and income amount. Call the
object’s methods to compute the tax due and pay the tax amount as
described in Step 7 above.
9. Call the toString methods of both accounts and
the taxpayment object to return the state (field
values) of the objects.
For example, a user Robert earns $24,000 per year, has $2,000.00 initially in his checking account, earns 3% annually on his $10,000.00 savings account, and deducts the following checks from his checking account (these check amounts will be listed one per line in the file check.txt):
359.00 112.42 10.03 75.00 223.59 48.86
After the TaxApp application executes, the following messages will be printed:
A check for the
amount of: $3600.00 has been sent to the IRS to pay the taxes of Robert.
(15% of $24,000)
The checking account
balance is now $100.00.
(After deducting checks, $1.50 transaction fee, and $3600 taxes. Always leave at least $100 in the checking account.)
The savings account
balance is now $7494.60.
(Interest of $25.00 added; then $2530.40 transferred to checking)
For extra credit: Add a static (class) variable to the Account class to assign unique, consecutive integer account numbers to each new account created. Add the account number to the toString method so that it will be returned.
Deliverables: as announced in the labs and explained in the handouts given to you in the labs.