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
Test Cases
※ Output examples follow programming industry standards
Input:
10000 5000 3000
Expected Output:
Initial balance: 10000 yen After deposit: 15000 yen After withdrawal: 12000 yen
Input:
0 1000 500
Expected Output:
Initial balance: 0 yen After deposit: 1000 yen After withdrawal: 500 yen
Input:
5000 0 1000
Expected Output:
Initial balance: 5000 yen After deposit: 5000 yen After withdrawal: 4000 yen
Input:
20000 10000 5000
Expected Output:
Initial balance: 20000 yen After deposit: 30000 yen After withdrawal: 25000 yen
❌ Some tests failed
Your Solution
Current Mode:● My Code
BankAccount.java🔒
Solution.java🔒
2/6 ファイル100B
⚠️警告
- No main method found
9
1
2
3
4
›
⌄
import java.util.Scanner;
class BankAccount {
}
0 B / 5 MB
You have 9 free executions remaining
