private double checkIfTransactionsExist(boolean checkAll) { double amount = 0.0; for (Transaction t : transactions) amount += t.getAmount(); return amount; }
private boolean isThereWithdrawl() { long diff = 0; long diffDays = 0; Date now = DateProvider.getInstance().now(); Date transactionDate = null; for (Transaction t : transactions) { if (t.getAmount() < 0) { transactionDate = t.getTransactionDate(); diff = now.getTime() - transactionDate.getTime(); diffDays = diff / (24 * 60 * 60 * 1000) + 1; if (diffDays < 10) { return true; } } } return false; }
/** @return Total interest earned on this account */ public double interestEarned() { double amount = 0.0; Map<Date, List<Transaction>> dailyTransactions = getTransactions(); List<Date> dates = new ArrayList<Date>(dailyTransactions.keySet()); Date lastWithdrawalDate = null; // Interate though transactions on each day and calculate the daily interest for (int index = dates.size() - 1; index >= 0; index--) { // Iterate through transactions looking for a Withdrawal. for (Transaction t : dailyTransactions.get(dates.get(index))) { if (t.getType() == TransactionType.WITHDRAWAL) { lastWithdrawalDate = t.getTransactionDate(); break; } } } // Calculate the daily amount with interest for (Date transactionDate : dailyTransactions.keySet()) { amount += calculateAmountWithInterest(transactionDate, lastWithdrawalDate, amount); } return amount; }