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 all 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
69 changes: 69 additions & 0 deletions Account.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
}
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