0% found this document useful (0 votes)
21 views

Inheritance Exercises: Private Double Balance Private Int Accountnumber Accountnumber

The document describes an inheritance exercise to create a banking program with account classes. It involves: 1) Creating an Account class with balance and accountNumber attributes and deposit/withdraw methods. 2) Deriving SavingsAccount and CurrentAccount classes from Account, adding interest and overdraft attributes. 3) Creating a Bank class with an array of Account objects, including objects of SavingsAccount and CurrentAccount. 4) Writing a update method in Bank to add interest to savings accounts and send letters to overdraft current accounts.

Uploaded by

Louze Anas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Inheritance Exercises: Private Double Balance Private Int Accountnumber Accountnumber

The document describes an inheritance exercise to create a banking program with account classes. It involves: 1) Creating an Account class with balance and accountNumber attributes and deposit/withdraw methods. 2) Deriving SavingsAccount and CurrentAccount classes from Account, adding interest and overdraft attributes. 3) Creating a Bank class with an array of Account objects, including objects of SavingsAccount and CurrentAccount. 4) Writing a update method in Bank to add interest to savings accounts and send letters to overdraft current accounts.

Uploaded by

Louze Anas
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Inheritance exercises

• Create Account class which contains:

private double balance; //The current balance


private int accountNumber; //The account number
// Constructor Account(int accountNumber)
// Setters and getters
// Withdraw and deposit methods
// PrintInfo method

• Write a main method in a different class to briefly experiment with some instances of
the Account class.
• Using the Account class as a base class, write two derived classes called SavingsAccount
and CurrentAccount.
o A SavingsAccount object, in addition to the attributes of an Account object,
should have an interest variable and a method which adds interest to the
account.
o A CurrentAccount object, in addition to the attributes of an Account object,
should have an overdraft limit variable. Ensure that you have overridden
methods of the Account class as necessary in both derived classes.
• Now create a Bank class, an object of which contains an array of Account objects.
Accounts in the array could be instances of the Account class, the SavingsAccount class,
or the CurrentAccount class. Create some test accounts (some of each type).
• Write an update method in the bank class. It iterates through each account, updating it
in the following ways: Savings accounts get interest added (via the method you already
wrote); CurrentAccounts get a letter sent if they are in overdraft.
• The Bank class requires methods for opening and closing accounts, and for paying a
dividend into each account.

Hints:

• Note that the balance of an account may only be modified through the deposit(double)
and withdraw(double) methods.
• The Account class should not need to be modified at all.
• Be sure to test what you have done after each step.

You might also like