009-001-010
Private Modifier: Complete Encapsulation
Hard
Problem Description
Private Modifier: Complete Encapsulation
In this problem, you will create a program that implements a SafeBankAccount class with a private field and business logic, reads operation parameters from standard input, and displays the result of each operation to standard output.
Learning Objective: Design an encapsulated class with business logic
Overview
Create a bank account class with balance management business logic.
Specifications
- Create a
SafeBankAccountclass - Private int field
balance - constructor sets initial balance (0 if negative)
deposit(int amount)for deposit (positive only)withdraw(int amount)for withdrawal (positive and within balance)getBalance()returns balance- Output results of all operations
Input Format
initialBalance
depositAmount
withdrawAmount (valid)
largeWithdrawAmount (exceeds balance)
Output Format
Initial: <initialBalance>
After deposit <depositAmount>: <balanceAfterDeposit>
After withdraw <withdrawAmount>: <balanceAfterWithdraw>
Invalid withdraw (<largeWithdrawAmount>): <balance>
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up