Write a BankAccount whose balance can change only through deposit and withdraw (validated), which records every successful transaction, and exposes the history read-only. Process commands from the input.
rejected: withdraw 9000
rejected: deposit -20
D 5000 -> 5000
W 1500 -> 3500
W 500 -> 3000
balance 3000
The balance and history are private and change together in one place, so they can never disagree. history() hands out a read-only span: callers can audit transactions but not forge them.
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!
We use Google Analytics cookies to see how LearnFrenzy is used and make it better, and Google AdSense to keep it free.
No analytics or ad cookies are set until you accept. Privacy Policy
·
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!