Lab 1 Details for MPCS 51050

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, Friday, April 18, 2014

Problem 1 (Singleton Pattern): 

Consider a rudimentary college registration system. A student will need to approach the registrar when he/she needs to register for a course. Since seating is limited in courses and the registrar is in charge of checking if seats on a course are still available, only one registrar should be allowed to exist in the system (to avoid write errors and make our life simpler).

What you need to implement:

You need to create a class called 'Registrar' in such a way that only one instance of the class can be created. If a second instance of the class is asked to be instantiated, your program should print an error message like " Sorry, a Registrar already exists" and return the existing instance. Test your code by trying to instantiate the Registrar class more than once.  Note that your singleton should be thread-safe.     

Problem 2 (Template Method Pattern): 

A new bank in your neighborhood offers two kinds of accounts:  Savings accounts and Checking accounts.  The savings account offers an annual interest rate of y (> 0 defined by you) where as there is no interest offered in the checking account.

What you need to implement:

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( ) does nothing in the base class 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 and are thus to be implemented in the base class 'Account'. 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 creating 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
.