Bank Account Operations in Java: Explanation & Practice
Create a full bank account class
Problem summary
Create a BankAccount class with deposit, withdraw, and balance check operations.
Starter code
// Create BankAccount with:
// - private double balance
// - void deposit(double amount)
// - boolean withdraw(double amount) - false if insufficient
// - double getBalance()
public class Main {
public static void main(String[] args) {
// Test case 1: start with 1000, deposit 500, withdraw 200
// Print: Balance: <result>
}
}Expected output and test cases
- 1000+500-200
Balance: 1300.0
- After failed withdraw
Balance: 500.0
- Multiple deposits
Balance: 2000.0
Hints
- Check balance before withdraw
- Return false if insufficient funds
- Deposit should always succeed
Related OOP Basics exercises
- Practice BMI Calculator Class in Java
- Practice Student Grade Calculator in Java
- Practice Shopping Cart in Java
Practice all OOP Basics exercises · Run this idea in the Java compiler