Assignment 2

:

Object creation, inheritance and polymorphism

The aim of this assignment is to write a simple program for a very small bank that has only two customers. Each customer has two types of accounts – a Hong Kong dollars saving account and a current account. Each type of account supports a Deposit and a Withdraw operation. For example, a Deposit(10.5) will add HKD$10.5 to the account, and Withdraw(6.5) will deduct HKD$6.5 from the account. You are asked to do the following: i) Create objects for the two customers with name James Bond and Goldfinger. Each customer object has a name, a unique account number, a saving account, and a current account. Initially, there is no money in all the accounts. ii) Deposit $100 and $300 respectively into the saving and current account of James Bond and $20000 and $50000 respectively into the saving and current accounts of Goldfinger. Store the customer objects in an array. Write a method that prints an account summary for all customers in the bank, i.e. a summary that looks like this Account holder: James Bond Account ID: 7 Account type: Saving account: $100 Current account: $300 Account holder: Account ID: Account type: Saving account: Current account: v) Goldfinger 8 $20,000 $50,000

iii) iv)

OK, now here is the difficult part. Add a new USD account that is created automatically for all account holders. There is no money in the account so the balance is 0. Print the account summary as in step (iv).

Here are some issues for you to consider: What are the objects? Are there any objects that we can group together and to provide a more generalized type? Could the more generalized type be used as base class and the more specialized type be used as subtype? Who should have the responsibility in printing the balance of the current account of James Bond? Find the simplest way in adding the new USD account and to print the summary without affecting the rest of the system.

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.