private void updateExistingTransactionsDetails(
     SavingsAccount account,
     Set<Long> existingTransactionIds,
     Set<Long> existingReversedTransactionIds) {
   existingTransactionIds.addAll(account.findExistingTransactionIds());
   existingReversedTransactionIds.addAll(account.findExistingReversedTransactionIds());
 }
Example #2
0
  public static void main(String[] args) {
    try {
      Context ctx = new InitialContext();
      Object objref = ctx.lookup(JNDI_NAME);

      SavingsAccountHome home =
          (SavingsAccountHome) PortableRemoteObject.narrow(objref, SavingsAccountHome.class);

      BigDecimal zeroAmount = new BigDecimal("0.00");
      SavingsAccount John = home.create("100", "John", "Smith", zeroAmount);

      System.out.println("Account Name: " + John.getFirstName());
      System.out.println("Credit: 88.50");

      John.credit(new BigDecimal("88.50"));
      System.out.println("Debit: 20.25");

      John.debit(new BigDecimal("20.25"));
      BigDecimal balance = John.getBalance();
      System.out.println("Balance = " + balance);
      // John.remove();
      System.exit(0);
    } catch (InsufficientBalanceException ex) {
      System.err.println("Caught an InsufficientBalanceException: " + ex.getMessage());
    } catch (Exception ex) {
      System.err.println("Caught an exception.");
      ex.printStackTrace();
    }
  }
 private void autoGenerateAccountNumber(final SavingsAccount account) {
   if (account.isAccountNumberRequiresAutoGeneration()) {
     final AccountNumberFormat accountNumberFormat =
         this.accountNumberFormatRepository.findByAccountType(EntityAccountType.SAVINGS);
     account.updateAccountNo(this.accountNumberGenerator.generate(account, accountNumberFormat));
     this.savingsAccountRepository.save(account);
   }
 }
Example #4
0
 public void withdraw(double amount) {
   if (uttakigjen > 0) {
     super.withdraw(amount);
     uttakigjen--;
   } else {
     throw new IllegalStateException("Ikke lov til å ta ut mer i år.");
   }
 }
  private void postJournalEntries(
      final SavingsAccount savingsAccount,
      final Set<Long> existingTransactionIds,
      final Set<Long> existingReversedTransactionIds,
      boolean isAccountTransfer) {

    final MonetaryCurrency currency = savingsAccount.getCurrency();
    final ApplicationCurrency applicationCurrency =
        this.applicationCurrencyRepositoryWrapper.findOneWithNotFoundDetection(currency);

    final Map<String, Object> accountingBridgeData =
        savingsAccount.deriveAccountingBridgeData(
            applicationCurrency.toData(),
            existingTransactionIds,
            existingReversedTransactionIds,
            isAccountTransfer);
    this.journalEntryWritePlatformService.createJournalEntriesForSavings(accountingBridgeData);
  }
Example #6
0
  public static void main(String[] args) {
    BankAccount ba1 = new ChequeAccount("Jack Black", "Hockey");
    ChequeAccount ca1 = new ChequeAccount("Chris Weidman", "Bunnies");
    ChequeAccount ca2 = new ChequeAccount("Ross Geller", "Dinosaurs");

    ba1.deposit(100);
    ((ChequeAccount) ba1).writeCheque(23);

    SavingsAccount sa1 = new SavingsAccount("David Letterman");
    SavingsAccount sa2 = new SavingsAccount("Jimmy Fallon");
    sa1.deposit(25);
    System.out.println("" + ba1 + ca1 + ca2 + sa1 + sa2);

    BalancePrinter bp = new BalancePrinter();
    bp.reportPrinter(ba1);
    bp.reportPrinter(ca1);
    bp.reportPrinter(ca2);
    bp.reportPrinter(sa1);
    bp.reportPrinter(sa2);
  } // main
  public static void main(String args[]) throws IOException {

    // Create a Scanner to read keyboard input.
    Scanner keyboard = new Scanner(System.in);

    // Ask user to enter annual interest rate
    System.out.print("Enter the savings account's " + "annual interest rate: ");
    double interestRate = keyboard.nextDouble();

    // close keyboard
    keyboard.close();

    DepositAndWithdrawalFiles depositAndWithdrawalFiles = new DepositAndWithdrawalFiles();
    SavingsAccount savingsAccount = depositAndWithdrawalFiles.new SavingsAccount(500, interestRate);

    // create a path to the deposit file
    Path depositPath =
        Paths.get("src/main/resources/com/levelup/java/exercises/beginner/Deposits.txt")
            .toAbsolutePath();

    // sum all lines in file and setting value in saving account
    double totalDeposits = Files.lines(depositPath).mapToDouble(Double::valueOf).sum();

    savingsAccount.deposit(totalDeposits);

    // create a path to the withdrawls file
    Path withdrawlsPath =
        Paths.get("src/main/resources/com/levelup/java/exercises/beginner/Withdrawls.txt")
            .toAbsolutePath();

    // sum all lines in file and setting value in saving account
    double totalWithdrawls = Files.lines(withdrawlsPath).mapToDouble(Double::valueOf).sum();

    savingsAccount.withdraw(totalWithdrawls);

    // Get the balance before adding interest.
    double priorBalance = savingsAccount.getAccountBalance();

    // Add the interest.
    savingsAccount.addInterest();

    // Get the interest earned.
    double interestEarned = savingsAccount.getLastAmountOfInterestEarned();

    // Create a DecimalFormat object for formatting output.
    DecimalFormat dollar = new DecimalFormat("#,##0.00");

    // Show user interest earned and balance.
    System.out.println("Interest earned: $" + dollar.format(interestEarned));

    System.out.println("Prior balance: $" + dollar.format(priorBalance));

    System.out.println("Ending balance: $" + dollar.format(savingsAccount.getAccountBalance()));
  }
  public static void main(String[] args) {

    String lineSeparator = "-------------------";
    SavingsAccount tomSavingsAccount = new SavingsAccount();
    SavingsAccount jimSavingsAccount =
        new SavingsAccount(4.0f, "AMEX", 2015, 500.00f, 2005, "Bank Account");

    System.out.println(lineSeparator);
    System.out.println("Tom's Savings Account");
    tomSavingsAccount.printDescription();
    System.out.println(lineSeparator);
    System.out.println("Jim's Savings Account");
    jimSavingsAccount.printDescription();
    System.out.println(lineSeparator);

    SavingsAccount anitaSavingsAccount = new SavingsAccount("HSBC", 1022);
    System.out.println("Anita's Savings Account");
    anitaSavingsAccount.printDescription();
    System.out.println(lineSeparator);
  }
Example #9
0
 public void endYearUpdate() {
   super.endYearUpdate();
   this.uttakigjen = this.maks;
 }
  public static void main(String[] args) throws IOException {

    String input;
    int numberOfMonths;
    double interestRate,
        startingBalance,
        deposit,
        withdrawal,
        balance = 0,
        totalDeposits = 0, // accumulator
        totalWithdrawals = 0, // accumulator
        totalInterest = 0; // accumulator

    input = JOptionPane.showInputDialog("Enter the annual interest rate as a percentage.");
    interestRate = Double.parseDouble(input);
    interestRate /= 100;

    input = JOptionPane.showInputDialog("Enter the account's starting balance.");
    startingBalance = Double.parseDouble(input);

    SavingsAccount account = new SavingsAccount(interestRate, startingBalance);

    input = JOptionPane.showInputDialog("Enter the number of months since the account opened.");
    numberOfMonths = Integer.parseInt(input);

    for (int i = 1; i <= numberOfMonths; i++) {

      input = JOptionPane.showInputDialog("Enter total deposits for month " + i + ":");
      deposit = Double.parseDouble(input);
      balance = account.addDeposit(deposit);

      input = JOptionPane.showInputDialog("Enter total withdrawals for month " + i + ":");
      withdrawal = Double.parseDouble(input);
      balance = account.subtractWithdrawal(withdrawal);

      balance = account.addMonthlyInterest();

      totalDeposits = totalDeposits + deposit;
      totalWithdrawals = totalWithdrawals + withdrawal;
      totalInterest = account.getInterestEarned();
    }

    DecimalFormat formatter = new DecimalFormat("#0.00");

    JOptionPane.showMessageDialog(
        null,
        "Balance is "
            + formatter.format(balance)
            + ".\n"
            + "Total deposits are "
            + totalDeposits
            + ".\n"
            + "Total withdrawals are "
            + totalWithdrawals
            + ".\n"
            + "Total interest is "
            + formatter.format(totalInterest)
            + ".\n");

    System.exit(0);
  }