Skip to content
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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions Account.java
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;
Copy link
Collaborator

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.

private AccountType accountType;
private String name;
private Class<? extends Contract> contractClass;
protected HashSet<Contract> contracts;


void addContract(Contract contract) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there be a removeContract functionality?

Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

9 changes: 9 additions & 0 deletions AccountType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package accounting;

public enum AccountType {
ASSET,
LIABILITY,
EQUITY,
INCOME,
EXPENSES
}
Loading