generated from fmigeon/estore-public
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Account.java
58 lines (47 loc) · 1.48 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
46
47
48
49
50
51
52
53
54
55
56
57
58
package estore.services.implem;
import estore.services.interfaces.IAdminAccount;
import estore.services.interfaces.IBusinessAccount;
import estore.services.interfaces.IConsultAccount;
import estorePojo.exceptions.InsufficientBalanceException;
public class Account implements IConsultAccount, IAdminAccount, IBusinessAccount {
private double amount;
private String owner;
@Override
public String getOwner() {
return owner;
}
@Override
public void setOwner(String owner) {
this.owner = owner;
}
@Override
public double getAmount() {
return amount;
}
@Override
public void setAmount(double amount) {
this.amount = amount;
}
@Override
public void credit(double amount) {
this.amount += amount;
}
@Override
public void withdraw(double amount) throws InsufficientBalanceException {
if ( this.amount < amount )
throw new InsufficientBalanceException(owner);
this.amount -= amount;
}
/**
* Two AccountImpl instances are considered equals
* if they share the same owner.
* Of course, in a more realistic implementation,
* we should have a account number.
*/
public boolean equals( Object other ) {
if( ! (other instanceof Account) )
return false;
Account otherAccount = (Account) other;
return ( otherAccount.owner == owner);
}
}