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 to the subversion repository according to the directions below.
All coding must be done in the Java Programming Language.Lab 1 Due: 5:00 pm, Monday, April 1, 2024
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 to the subversion repository in the
pre-existing folder named "labN" (where N is the homework
number). Please include a README text file that contains any
instructions for the TAs to assist with grading, and design
notes are often the most useful thing you can provide. We do not
usually need any info on how to compile your code unless your
code layout is arcane.