Each lab will consist of a small problem and details of how to proceed. You need to submit labs to the TAs for grading--see submission instructions below. Generally, unless otherwise specified, you will have one week to complete each assigned lab.
See the syllabus for information on grading. Turning in lab assignments is required. Submit your assignments as a tarball to the subversion repository according to the directions below.
You may write these solutions in either Java or C++...your choice.
Lab 1 Due: 5:00 pm, Monday, July 7, 2014
Problem 1
(Singleton Pattern & Template Method Pattern):
The bank you work for (you only work for one bank, of course) offers two kinds of accounts: Savings accounts and Checking accounts. The savings account offers an annual interest rate of y (> 0 defined by you) whereas there is no interest offered in the checking account. Make sure you read and thoroughly understand Gamma et. al. on the Template Method and Singleton patterns.
What
you need to implement:
A Bank
class that is implemented as a Singleton. Therefore, no code in
your program should be able to instantiate more than one Bank during a
single execution of your code.
A bank has multiple Accounts. Create an abstract class called 'Account'. This class will have a Template Method called GetAccountSummary( ). This method in turn calls 3 other methods: CalcInterest( ), UpdateBalance( ) and PrintSummary( ). (Note that CalcInterest( ) cannot be implemented in the base class (as it's abstract) and is overridden by subclasses).
Create two more classes SavingsAccount and CheckingAccount, that are derived from Account. Both the derived classes implement their own CalcInterest( ) method (which returns any interest that might have accrued) . The methods UpdateBalance( ) and PrintSummary( ) are generic to all types of Accounts and are thus to be implemented in the base class 'Account' in its GetAccountSummary() Template Method. Implement any other variables, methods that you feel are needed for these classes to function e.g. you may need a private variable called 'balance'.
Test your implementation by instantiating a Bank with the two kinds of accounts with an initial balance and asking both of them for account summaries. (To simplify the problem you can assume that interest is compounded on the first of January every year). You can also assume that the user inputs the current date, or you can use the system date.
Submitting:
Submit your assignments in a folder called LAB1 to the subversion
repository. Place all of your Lab 1 work into
one folder. You will only be graded on your material within a
reasonably labeled folder. Also, please include a README text file that
contains any instructions for the TAs to assist with grading, such as how to compile, run, or even understand
your code.
From now on, each Lab Deliverable should be submitted as
described here. Each assignment should have its own folder with its own README inside of it. Please ask
for assistance if you have any questions.