forked from INET-Complexity/Core-ESL
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAccount.java
More file actions
69 lines (55 loc) · 1.66 KB
/
Account.java
File metadata and controls
69 lines (55 loc) · 1.66 KB
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
59
60
61
62
63
64
65
66
67
68
69
package accounting;
import agents.Agent;
import actions.Action;
import contracts.Contract;
import java.util.ArrayList;
import java.util.HashSet;
class Account {
private Account(String name, AccountType accountType, Double startingBalance) {
this.name = name;
this.accountType = accountType;
this.balance = startingBalance;
}
Account(String name, AccountType accountType) {
this(name,accountType,0.0);
}
private double balance;
static void doubleEntry(Account debitAccount, Account creditAccount, double amount) {
debitAccount.debit(amount);
creditAccount.credit(amount);
}
// private Collateral collateralType;
private AccountType accountType;
private String name;
/**
* A Debit is a positive change for ASSET and EXPENSES accounts, and negative for the rest.
* @param amount the amount to debit
*/
private void debit(double amount) {
if ((accountType==AccountType.ASSET) || (accountType==AccountType.EXPENSES)) {
balance += amount;
} else {
balance -= amount;
}
}
/**
* A Credit is a negative change for ASSET and EXPENSES accounts, and positive for the rest.
* @param amount the amount to credit
*/
private void credit(double amount) {
if ((accountType==AccountType.ASSET) || (accountType==AccountType.EXPENSES)) {
balance -= amount;
} else {
balance += amount;
}
}
AccountType getAccountType() {
return accountType;
}
double getBalance() {
return balance;
}
String getName() {
return name;
}
}