Skip to content

Practice Problem 12

Seanti edited this page Mar 26, 2025 · 1 revision

Problem:

  1. Create a BankAccount class with attributes:

    • accountNumber (String)

    • balance (double)

  2. Add methods for:

    • deposit(double amount): Adds money to the account.

    • withdraw(double amount): Deducts money (check if balance is enough).

    • displayBalance(): Displays the balance.

  3. In main(), create an object of BankAccount and test all methods.


Sample Output:

Enter account number: 123456  
Enter initial balance: 5000  

1 - Deposit  
2 - Withdraw  
3 - Check Balance  
4 - Exit  
Enter your choice: 1  
Enter deposit amount: 2000  
Deposit successful!  

1 - Deposit  
2 - Withdraw  
3 - Check Balance  
4 - Exit  
Enter your choice: 2  
Enter withdrawal amount: 3000  
Withdrawal successful!  

1 - Deposit  
2 - Withdraw  
3 - Check Balance  
4 - Exit  
Enter your choice: 3  
Current balance: 4000  

1 - Deposit  
2 - Withdraw  
3 - Check Balance  
4 - Exit  
Enter your choice: 4  
Exiting program.

Clone this wiki locally