โ Back to Encapsulation
Question 474
Encapsulated Bank Account
Encapsulated Bank Account
Build a classBankAccountfrom scratch. Requirements: - aprivate doublebalance set by the constructor from a starting amount -Deposit(double amount)adds to the balance, but ignores a negativeamount-Withdraw(double amount)subtracts from the balance, but ignores a negativeamountand ignores any withdrawal larger than the current balance - a read-onlyBalanceproperty returns the balance Do not write aMainmethod. Starting at 100, afterDeposit(50)thenWithdraw(30)the program prints: 120
Expected Output:
120
Topics:
Encapsulation
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (cw, cr, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.