You are on page 1of 2

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.

iii) Store the customer objects in an array.

iv) 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: Goldfinger


Account ID: 8
Account type:
Saving account: $20,000
Current account: $50,000

v) 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.