Bank Account Modeling
This program models bank account using OOP.
Problem Statement
Write a Java program to model BankAccount class with deposit and withdraw methods.
Source Code
| 1 | class BankAccount { |
| 2 | String owner; double balance; |
| 3 | BankAccount(String o,double b){ owner=o; balance=b; } |
| 4 | void deposit(double amt){ balance+=amt; } |
| 5 | void withdraw(double amt){ balance-=amt; } |
| 6 | void show(){ System.out.println(owner+"'s balance: "+balance); } |
| 7 | } |
| 8 | public class BankAccountModel { |
| 9 | public static void main(String[] args) { |
| 10 | System.out.println("Eduinq Bank Account Modeling"); |
| 11 | BankAccount b=new BankAccount("Arun",1000); |
| 12 | b.deposit(500); b.withdraw(200); b.show(); |
| 13 | } |
| 14 | } |
Program Output
Eduinq Bank Account Modeling Arun's balance: 1300.0
Explanation
Class models real world bank account. - Methods perform deposit and withdraw operations. - Encapsulation ensures account balance managed through methods. Conclusion: Shows how to model real world bank account.