Skip to content

feat(other): add basic BankAccount OOP class (v3)#14549

Open
nickzerjeski wants to merge 1 commit intoTheAlgorithms:masterfrom
nickzerjeski:renew-bank-account-14024-v2
Open

feat(other): add basic BankAccount OOP class (v3)#14549
nickzerjeski wants to merge 1 commit intoTheAlgorithms:masterfrom
nickzerjeski:renew-bank-account-14024-v2

Conversation

@nickzerjeski
Copy link
Copy Markdown

Describe your change:

Fixes #14024

  • Add an algorithm?
  • Fix a bug or typo in an existing algorithm?
  • Add or change doctests? -- Note: Please avoid changing both code and tests in a single pull request.
  • Documentation change?

Checklist:

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized.
  • I know that pull requests will not be merged if they fail the automated tests.
  • This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • All new Python files are placed inside an existing directory.
  • All filenames are in all lowercase characters with no spaces or dashes.
  • All functions and variable names follow Python naming conventions.
  • All function parameters and return values are annotated with Python type hints.
  • All functions have doctests that pass the automated testing.
  • All new algorithms include at least one URL that points to Wikipedia or another similar explanation.
  • If this pull request resolves one or more open issues then the description above includes the issue number(s) with a closing keyword: "Fixes #ISSUE-NUMBER".

Copilot AI review requested due to automatic review settings April 13, 2026 09:13
@algorithms-keeper algorithms-keeper bot added the awaiting reviews This PR is ready to be reviewed label Apr 13, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new BankAccount class under other/ intended to demonstrate basic OOP concepts (encapsulation via properties, simple state updates) and includes inline doctests.

Changes:

  • Introduces BankAccount with validated initialization, balance accessor, deposit(), and withdraw().
  • Adds doctest examples in the class docstring and a __main__ doctest runner.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,60 @@
"""
Simple BankAccount class demonstrating core OOP concepts.
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module docstring doesn’t include any source/explanation URL. New submissions in this repo typically include at least one link in the header docstring/comment to help readers (see CONTRIBUTING.md:57 and e.g. other/graham_scan.py:2-6). Consider adding a relevant reference link for the concept being demonstrated.

Suggested change
Simple BankAccount class demonstrating core OOP concepts.
Simple BankAccount class demonstrating core OOP concepts.
Reference:
https://docs.python.org/3/tutorial/classes.html

Copilot uses AI. Check for mistakes.
>>> account.withdraw(20)
130.0
>>> account.account_number
'ACC-1001'
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doctests currently cover only the happy path. This repo often includes doctests for erroneous inputs/exceptions as well (e.g., financial/interest.py:20-31). Consider adding doctests for the validation branches (empty account_number, negative initial_balance, non-positive deposit/withdraw, withdraw exceeding balance) to ensure those errors are exercised.

Suggested change
'ACC-1001'
'ACC-1001'
>>> BankAccount("", initial_balance=10.0)
Traceback (most recent call last):
...
ValueError: account_number must be provided
>>> BankAccount("ACC-1002", initial_balance=-1.0)
Traceback (most recent call last):
...
ValueError: initial_balance cannot be negative
>>> account.deposit(0)
Traceback (most recent call last):
...
ValueError: deposit amount must be positive
>>> account.withdraw(0)
Traceback (most recent call last):
...
ValueError: withdraw amount must be positive
>>> account.withdraw(1000)
Traceback (most recent call last):
...
ValueError: insufficient funds

Copilot uses AI. Check for mistakes.
Comment on lines +2 to +9
Simple BankAccount class demonstrating core OOP concepts.
"""


class BankAccount:
"""
Basic bank account model with encapsulated account number and balance.

Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file reads more like an OOP tutorial/example than an algorithm or data-structure implementation, which may conflict with the project’s contribution guidelines about avoiding “how-to examples” and focusing on algorithms with unique computational value (CONTRIBUTING.md:41-62). If it’s intended to stay, consider clarifying in the module/class docstring what algorithmic concept is being implemented and why it belongs in this repository.

Suggested change
Simple BankAccount class demonstrating core OOP concepts.
"""
class BankAccount:
"""
Basic bank account model with encapsulated account number and balance.
Invariant-preserving bank account state model.
This module implements a minimal transactional data model whose computational
value is the enforcement of account invariants during constant-time state
transitions: account identifiers must be present, balances may not start
negative, deposits must be positive, and withdrawals may not overdraw the
account.
"""
class BankAccount:
"""
Stateful account abstraction with validated balance updates.
The class is intentionally small, but its purpose is not to serve as a
generic OOP tutorial. It provides a compact example of how to model a
mutable record while preserving correctness constraints across operations,
with each transaction executing in O(1) time.

Copilot uses AI. Check for mistakes.
@algorithms-keeper algorithms-keeper bot added the tests are failing Do not merge until tests pass label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviews This PR is ready to be reviewed tests are failing Do not merge until tests pass

Projects

None yet

2 participants