In-Class Assignment #7
For this assignment, you will create three very small classes, that model various kinds of Bank Accounts.
To get you started, you may download or copy
~lallip/perl/BankAccount.pm. This contains the framework
for your first class. It has a constructor named new, and defines
three data elements: name, account_num,
and balance. All three of these data elements are passed into
the constructor. It also has accessors for all three of these data elements.
Add to this class two methods, deposit and withdraw.
Each takes an amount as an argument, and modifies the account's balance
by that amount.
Write a new class, InterestAccount, which inherits from
BankAccount. This class defines one additional data element,
rate. Write a constructor named new which takes
the name, account_num, balance, and rate. It calls the Super class's constructor,
then adds the rate. Write one additional method for this class, accrue.
When called, it increases the account's balance by (rate * balance).
Write a third class, CheckingAccount, which also inherits from
BankAccount. This class defines one additional data element,
checks. Write a constructor named new which takes
the name, account_num, balance, and checks. It calls the Super class's constructor,
then adds the checks. Write two additional methods, order_checks
and write_check. The first takes a number of checks to order, and
increases checks by that amount. The second takes an amount of money,
withdraws that much money from the account, and decrements the checks by 1. If
there are no checks available in the account, carp out a warning message
and do not change the balance or checks.
For a ½ bonus point, write a fourth class, InterestCheckingAccount,
which inherits from both InterestAccount and CheckingAccount.
You will need to write a new constructor that takes all five data elements.
You need not write any additional methods, but you must verify that all methods of all
parent classes are functional.
(This bonus is actually fairly easy once you've gotten the main assignment done, but keep in mind that no bonus points are awarded unless the main assignment is completed successfully.)
Testing
To test your code, I have written ~lallip/perl/ica7.pl.
It tests all of your modules, including the bonus if it exists. In order to get full credit,
all of the 60 main tests must pass. In order to get bonus credit, all 96 of the tests must pass.
Code Reuse
Keep in mind one of the benefits of inheritance is the ability to reuse existing code.
Therefore, none of your children modules should be rewriting any subroutines it can
inherit from its parent module. The tests in ica7.pl test for this as well.
Submission Instructions
Connect to solaris.remote.cs.rpi.edu and execute
~lallip/public/submit.pl. You need not use the h2xs program
to create your frameworks if you do not wish to. You need not document your modules nor
write any additional tests (though you are certainly free to do so if you believe it would
help). Submit only your three or four .pm files.
You may submit infinite times, only the last submission is graded. Your final submission is due at 4pm today, Thursday, March 25, 2010
