0% found this document useful (0 votes)
2 views2 pages

You Are Developing A Banking System With A Base C

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 2

You are developing a banki…

You are developing a banking system with a base class Account and derived classes
SavingsAccount and CurrentAccount.Questions:Define the Account class with attributes like
accountNumber, accountHolderName, and balance. Write the class definition.The
SavingsAccount class should have an additional attribute interestRate. How would you define
this class and its constructor?The CurrentAccount class should have an additional attribute
overdraftLimit. How would you define this class and its constructor?Write a method
displayAccountInfo() in the Account class to show account information. How would you override
this method in the SavingsAccount and CurrentAccount classes?

Defining the Bank Account Classes

Account Class
This class serves as the base class for all account types.

Python

class Account:
def __init__(self, accountNumber, accountHolderName, balance):
self.accountNumber = accountNumber
self.accountHolderName = accountHolderName
self.balance = balance

def displayAccountInfo(self):
print("Account Number:", self.accountNumber)
print("Account Holder Name:", self.accountHolderName)
print("Balance:", self.balance)
SavingsAccount Class
This class inherits from the Account class and adds an interest rate attribute.

Python

class SavingsAccount(Account):
def __init__(self, accountNumber, accountHolderName, balance,
interestRate):
super().__init__(accountNumber, accountHolderName, balance)
self.interestRate = interestRate
def displayAccountInfo(self):
super().displayAccountInfo()
print("Interest Rate:", self.interestRate)
CurrentAccount Class
This class inherits from the Account class and adds an overdraft limit attribute.

Python

class CurrentAccount(Account):
def __init__(self, accountNumber, accountHolderName, balance,
overdraftLimit):
super().__init__(accountNumber, accountHolderName, balance)
self.overdraftLimit = overdraftLimit

def displayAccountInfo(self):
super().displayAccountInfo()
print("Overdraft Limit:", self.overdraftLimit)
Explanation
● Account class: Defines the basic attributes and methods common to all account types.
● SavingsAccount class: Inherits from Account and adds the interestRate attribute. Overrides
the displayAccountInfo method to include interest rate information.
● CurrentAccount class: Inherits from Account and adds the overdraftLimit attribute. Overrides
the displayAccountInfo method to include overdraft limit information.
Note: While this code provides a basic structure, a real-world banking system would require additional
methods for deposit, withdrawal, interest calculation, overdraft handling, and error handling. Also,
consider using properties to encapsulate data and provide data validation.
By using inheritance, we've created a flexible framework for different account types, reusing common
code from the base class.
Would you like to add methods for deposit, withdrawal, or interest calculation?
Sources
1. https://github.com/Levi-cell/PythonZero

You might also like