Project: Bank Account Class System
Project: Bank Account Class System
In this end-of-chapter project, we unify all key Object-Oriented concepts covered in this module—Classes, Encapsulation, Inheritance, Method Overriding, Polymorphism, and Abstraction—to architect a comprehensive Banking System Engine.
1. System Architecture & Requirements
Our system models a financial institution managing multiple account types:
- 1
Account(Abstract Base Class): Defines the common interface and encapsulates state (account_number,holder_name, and protected_balance). - 2
SavingsAccount(Subclass): Requires a minimum balance and supports accruing monthly interest. - 3
CheckingAccount(Subclass): Permits an overdraft limit for transactions exceeding available funds, with per-transaction overdraft fees. - 4Transaction Logging: Automatically tracks timestamped audit logs for every deposit and withdrawal.
- 5Polymorphic Bank Manager: Iterates over heterogeneous accounts to execute monthly maintenance routines seamlessly.
2. Complete Object-Oriented Code
3. Execution Simulation
Multiple Choice Questions
1. In this project, what stops an external script from instantiating Account("AC-1", "Test") directly?
A. Python file permissions B. Account inherits from ABC and defines unimplemented @abstractmethods C. The Account class is private D. It has no __init__ constructor Answer: B Explanation: Inheriting from abc.ABC with at least one @abstractmethod makes the class abstract, preventing direct instantiation.
2. How is data encapsulation preserved for the account's cash balance?
A. Storing it as a read-only @property wrapping the protected _balance attribute B. Making the variable global C. Writing the balance to an encrypted text file after every call D. Defining balance as a static method Answer: A Explanation: Storing balance in self._balance and exposing it via a @property allows external callers to read the balance without directly writing arbitrary values to it.
3. Which OOP principle allows bank.run_monthly_audit() to call .monthly_maintenance() on both savings and checking accounts without checking their exact class?
A. Data Sharding B. Polymorphism C. Composition D. Garbage Collection Answer: B Explanation: Polymorphism enables a single loop to invoke the same method name (monthly_maintenance) across diverse object types, executing each class's custom logic automatically.
4. What does the CheckingAccount class do when a withdrawal pushes the balance below zero?
A. It throws an unrecoverable AssertionError B. It permits the transaction up to its overdraft_limit and applies a transaction fee C. It transfers funds from the nearest savings account automatically D. It resets the balance to zero Answer: B Explanation: The overridden withdraw() method in CheckingAccount checks against -self.overdraft_limit and tacks on self.transaction_fee.
5. Why does SavingsAccount.__init__ call super().__init__(account_no, holder_name, initial_deposit)?
A. To invoke the abstract base class's constructor and initialize shared attributes B. To create an SQLite database table C. To prevent other classes from subclassing SavingsAccount D. To convert all numbers into floating-point decimals Answer: A Explanation: super().__init__() calls the parent Account constructor to properly initialize common fields and record the opening transaction in the ledger.
Types of Exceptions
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
| Previous Lesson | Next Lesson |
|---|---|
| Encapsulation and Abstraction | Types of Exceptions |
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.