-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBankAccounts.java
More file actions
35 lines (31 loc) · 932 Bytes
/
BankAccounts.java
File metadata and controls
35 lines (31 loc) · 932 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
class Account {
double balance;
String accountHolder;
protected void debit(double amount) {
if (this.balance < amount) {
System.out.println("Insufficient Balance");
} else {
this.balance -= amount;
System.out.println("Transaction Successful");
}
System.out.println("Balance : " + this.balance);
}
protected void credit(double amount) {
this.balance += amount;
System.out.println("Credit Successful ");
System.out.println("Updated Balance : " + this.balance);
}
}
public class BankAccounts {
public static void main(String[] args) {
Account a1 = new Account();
Account a2 = new Account();
a1.balance = 1000;
a1.accountHolder = "Bheru";
a2.balance = 1200;
a2.accountHolder = "Yusuf";
a1.debit(300);
a1.debit(701);
a1.credit(120);
}
}