-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Double Entry Accounting #4
base: master
Are you sure you want to change the base?
Changes from 4 commits
aa2ab65
c3b561b
2ac4b8b
a8299c2
e78734e
a4119a2
cb9c049
d225f11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package accounting; | ||
|
||
import agents.Agent; | ||
import actions.Action; | ||
import contracts.Contract; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
|
||
public class Account { | ||
|
||
private Account(String name, AccountType accountType, Double startingBalance) { | ||
this.name = name; | ||
this.accountType = accountType; | ||
this.balance = startingBalance; | ||
this.contractClass = null; | ||
this.contracts = new HashSet<>(); | ||
} | ||
|
||
Account(String name, AccountType accountType) { | ||
this(name,accountType,0.0); | ||
} | ||
|
||
private double balance; | ||
|
||
// private Collateral collateralType; | ||
private AccountType accountType; | ||
private String name; | ||
private Class<? extends Contract> contractClass; | ||
protected HashSet<Contract> contracts; | ||
|
||
|
||
void addContract(Contract contract) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it intentional that these functions scope are the Java default? It's likely that's best, but I didn't know if some, like addContract, should be public? |
||
contracts.add(contract); | ||
} | ||
|
||
/** | ||
* A Debit is a positive change for ASSET and EXPENSES accounts, and negative for the rest. | ||
* @param amount the amount to debit | ||
*/ | ||
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 | ||
*/ | ||
void credit(double amount) { | ||
if ((accountType==AccountType.ASSET) || (accountType==AccountType.EXPENSES)) { | ||
balance -= amount; | ||
} else { | ||
balance += amount; | ||
} | ||
} | ||
|
||
|
||
ArrayList<Action> getAvailableActions(Agent me) { | ||
ArrayList<Action> availableActions = new ArrayList<>(); | ||
for (Contract contract : contracts) { | ||
ArrayList<Action> contractActions = contract.getAvailableActions(me); | ||
if (contractActions != null) availableActions.addAll(contractActions); | ||
} | ||
return availableActions; | ||
} | ||
|
||
// public void setCollateralType(Collateral collateralType) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove? |
||
// this.collateralType = collateralType; | ||
// } | ||
|
||
AccountType getAccountType() { | ||
return accountType; | ||
} | ||
|
||
double getBalance() { | ||
return balance; | ||
} | ||
|
||
String getName() { | ||
return name; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be a removeContract functionality? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should the user be able to pull a list of the existing contracts in the contract hashSet? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package accounting; | ||
|
||
public enum AccountType { | ||
ASSET, | ||
LIABILITY, | ||
EQUITY, | ||
INCOME, | ||
EXPENSES | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove commented variables, unless it is a discussion point whether or not to add them.