forked from git-sumana/BankApplication
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BankAccount.java
35 lines (29 loc) · 906 Bytes
/
BankAccount.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
34
35
public class BankAccount {
private long accountNumber;
private String password;
private double balance;
public BankAccount(long accountNumber, String password, double balance) {
this.accountNumber = accountNumber;
this.password = password;
this.balance = balance;
}
public long getAccountNumber() {
return accountNumber;
}
public boolean validatePassword(String password) {
return this.password.equals(password);
}
public synchronized double getBalance() {
return balance;
}
public synchronized void deposit(double amount) {
balance += amount;
}
public synchronized void withdraw(double amount) {
if (amount <= balance) {
balance -= amount;
} else {
System.out.println("Insufficient balance.");
}
}
}