package jesse.keeblarcraft.BankMgr; import java.util.List; // Contains the information of an individuals player's bank account. // TODO: Add ability to store NBT data of items in the future so we can store not just money but items too // like a safety deposit box public class IndividualAccount { private String globalAccountNumber; private String bankLetterIdentifier; private String accountNumber; private String accountNumberAlias; private Integer routingNumber; // Will always be the bank it's in private List accountHolders; private List accountHolderUuids; private Integer accountBalance; private Boolean allowNegativeBalance; private Boolean accountLocked; private Integer accountType; // TODO: Replace with enum in future. Valid is "checking" and "savings" right now public IndividualAccount() {} public IndividualAccount(String accountNumber, Integer routingNumber, List holders, List accountHolderUuids, Boolean allowNegativeBalance, Integer initialBalance, String alias, Integer accountType, String bankLetterIdentifier) { System.out.println("Called to create new IndividualAccount with following values: " + accountNumber + " " + routingNumber + " " + holders + " " + accountHolderUuids + " " + allowNegativeBalance + " " + initialBalance + " " + alias + " " + accountType); this.accountNumber = accountNumber; this.routingNumber = routingNumber; this.accountHolders = holders; this.accountHolderUuids = accountHolderUuids; this.allowNegativeBalance = allowNegativeBalance; this.accountBalance = initialBalance; this.accountNumberAlias = alias; this.accountType = accountType; this.bankLetterIdentifier = bankLetterIdentifier; this.globalAccountNumber = bankLetterIdentifier + "-" + routingNumber + "-" + accountNumber; } // TODO: Make this a map in the future public void AddAccountHolder(String newHolder, String newHolderUuid) { if (!accountHolders.contains(newHolder)) { accountHolders.add(newHolder); } if (!accountHolderUuids.contains(newHolderUuid)) { accountHolderUuids.add(newHolderUuid); } } // May have unintended consequences if account can't go negative public void SetMoney(Integer amount) { System.out.println("Previous balance on account: " + this.accountBalance + ". New balance: " + amount); this.accountBalance = amount; } public void AliasAccount(String newAlias) { this.accountNumberAlias = newAlias; } public Boolean IsLocked() { return accountLocked; } public void LockAccount() { accountLocked = true; } public Boolean Deposit(Integer amount) { Boolean success = false; if (!accountLocked) { accountBalance += amount; success = true; } return success; } public Boolean Withdraw(Integer amount) { Boolean success = false; if (!accountLocked) { // Determine remaining balance Integer remaining = accountBalance - amount; success = (remaining < 0 && !allowNegativeBalance); // Complete the transaction if successful if (success) { accountBalance = remaining; } } return success; } public Boolean CanWithdraw(Integer amount) { Boolean canWithdraw = false; if (!accountLocked && (accountBalance - amount >= 0 || allowNegativeBalance)) { canWithdraw = true; } return canWithdraw; } public Boolean IsHolder(String name) { Boolean ret = false; if (accountHolders.contains(name)) { ret = true; } return ret; } public Boolean AllowsNegative() { return this.allowNegativeBalance; } public List GetAccountHolders() { return accountHolders; } public Integer GetAccountBalance() { return accountBalance; } public String GetAccountNumber() { return accountNumber; } public Integer GetRoutingNumber() { return routingNumber; } public String GetGlobalAccountNumber() { return globalAccountNumber; } }