-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.java
33 lines (30 loc) · 916 Bytes
/
Account.java
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
public class Account {
private int balance;
Account(int a){
this.balance = a;
}
protected void widthraw(int amount) {
if(this.isBalanceSufficient(amount)) {
int previousBal=this.balance;
this.balance = this.balance-amount;
System.out.println(this.toString(previousBal,amount,this.balance));// printing withdrawl details
}
else {
System.out.println("Insufficient Balance");
}
}
// this method can't be override and accessed outside this class
private boolean isBalanceSufficient(int amount) {
int bal = this.balance;
if((bal-amount)>=0) {
return true;
}
else {
return false;
}
}
public final String toString(int previousBal , int amount, int balance) {
String statement = "Previous bal. :"+String.valueOf(previousBal)+"\nDebited amt. :"+String.valueOf(amount)+"\nCurrent bal. :"+String.valueOf(balance);
return statement;
}
}