2024-11-05 00:45:28 +00:00
|
|
|
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 {
|
2024-11-07 01:01:41 +00:00
|
|
|
private Integer accountNumber;
|
2024-11-05 00:45:28 +00:00
|
|
|
private String accountNumberAlias;
|
2024-11-07 01:01:41 +00:00
|
|
|
private Integer routingNumber; // Will always be the bank it's in
|
2024-11-05 00:45:28 +00:00
|
|
|
private List<String> accountHolders;
|
|
|
|
private Integer accountBalance;
|
|
|
|
private Boolean allowNegativeBalance;
|
|
|
|
private Boolean accountLocked;
|
|
|
|
private String accountType; // TODO: Replace with enum in future. Valid is "checking" and "savings" right now
|
|
|
|
|
|
|
|
|
|
|
|
public IndividualAccount() {}
|
|
|
|
|
2024-11-07 01:01:41 +00:00
|
|
|
public IndividualAccount(Integer accountNumber, Integer routingNumber, List<String> holders,
|
2024-11-05 00:45:28 +00:00
|
|
|
Boolean allowNegativeBalance, Integer initialBalance, String alias) {
|
|
|
|
this.accountNumber = accountNumber;
|
|
|
|
this.routingNumber = routingNumber;
|
|
|
|
this.accountHolders = holders;
|
|
|
|
this.allowNegativeBalance = allowNegativeBalance;
|
|
|
|
this.accountBalance = initialBalance;
|
|
|
|
this.accountNumberAlias = alias;
|
|
|
|
}
|
|
|
|
|
2024-11-07 01:01:41 +00:00
|
|
|
public void AddAccountHolder(String newHolder) {
|
|
|
|
if (!accountHolders.contains(newHolder)) {
|
|
|
|
accountHolders.add(newHolder);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-05 00:45:28 +00:00
|
|
|
public void AliasAccount(String newAlias) {
|
|
|
|
this.accountNumberAlias = newAlias;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Boolean IsLocked() {
|
|
|
|
return accountLocked;
|
|
|
|
}
|
|
|
|
|
2024-11-07 01:01:41 +00:00
|
|
|
public void LockAccount() {
|
|
|
|
accountLocked = true;
|
|
|
|
}
|
|
|
|
|
2024-11-05 00:45:28 +00:00
|
|
|
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) {
|
|
|
|
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<String> GetAccountHolders() {
|
|
|
|
return accountHolders;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Integer GetAccountBalance() {
|
|
|
|
return accountBalance;
|
|
|
|
}
|
|
|
|
|
2024-11-07 01:01:41 +00:00
|
|
|
public Integer GetAccountNumber() {
|
2024-11-05 00:45:28 +00:00
|
|
|
return accountNumber;
|
|
|
|
}
|
|
|
|
|
2024-11-07 01:01:41 +00:00
|
|
|
public Integer GetRoutingNumber() {
|
2024-11-05 00:45:28 +00:00
|
|
|
return routingNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|