-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccount.java
45 lines (37 loc) · 1.04 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
public class Account {
// Private variables
private int accountNumber;
private double balance;
// Constructors
public Account(int accountNumber, double balance) {
this.accountNumber = accountNumber;
this.balance = balance;
}
public Account(int accountNumber) {
this.accountNumber = accountNumber;
balance = 0;
}
// Public getters and setters for private variables
public int getAccountNumber() {
return accountNumber;
}
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void credit(double amount) {
balance += amount;
}
public void debit(double amount) {
if (balance < amount) {
System.out.println("amount withdrawn exceeds the current balance!");
} else {
balance -= amount;
}
}
public String toString() {
return String.format("A/C no: %d Balance=%.2f", accountNumber, balance);
}
}