009-001-003

Private Modifier: Bank Account Class

Hard

Problem Description

Private Modifier: Bank Account class

In this problem, you will create a program that implements a BankAccount class with a private field balance, and safely manipulates the balance through getter, setter, deposit, and withdrawal methods, displaying the result to standard output.

Learning Objective: Encapsulate fields with private modifier, control access with getter and setter

Create a bank account class. Make balance private and safely operate with deposit/withdraw methods.

Input

Line 1: Initial balance (integer)
Line 2: Deposit amount (integer)
Line 3: Withdrawal amount (integer)

Output

Initial balance: [amount] yen
After deposit: [amount] yen
After withdrawal: [amount] yen

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