Oop Revision Exam
Oop Revision Exam
OOP Revision
Problem 1 : Musician Class
A. Data Attributes
Write a class named Musician , which should have the following data attributes:
__name (for the name of the musician).
__instrument (for the instrument the musician plays, e.g., Guitar, Piano, Drums, etc.).
__genre (for the music genre the musician specializes in, e.g., Rock, Jazz, Classical, etc.).
__albums (a list to store the albums released by the musician, initially an empty list).
__awards (a list to store the awards received by the musician, initially an empty list).
Requirements:
1. Base Class: BankAccount (10 Marks)
Define a class called BankAccount with the following attributes:
account_number : A unique identifier for the account.
account_holder : The name of the account holder.
balance : The current balance in the account.
Define the following methods:
deposit(amount) : Adds money to the balance.
withdraw(amount) : Subtracts money from the balance.
get_balance() : Returns the current balance in the account.
transfer(amount, target_account) : Transfers money to another account.
(Hint: Ensure that withdrawal does not exceed the balance.)
2. Derived Classes: SavingsAccount and CheckingAccount (10 Marks)
Define two classes called SavingsAccount and CheckingAccount that inherit from BankAccount :
SavingsAccount :
Adds an attribute interest_rate (default: 0.02) to represent the interest rate.
Overrides the deposit() method to add interest based on the interest_rate
whenever money is deposited.
CheckingAccount :
Adds an attribute overdraft_limit (default: 500) to represent the overdraft limit
allowed.
Overrides the withdraw() method to allow withdrawals beyond the balance, but only if
it does not exceed the overdraft limit.
3. BankSystem Class (10 Marks)
Define a class called BankSystem to manage all bank accounts:
add_account(account) : Adds an account to the system.
get_account(account_number) : Returns the account with the given account number.
display_all_accounts() : Displays the details of all accounts in the system.
Page 2 of 2