Advertisement
AlexandrP

BaseDeposit

Mar 17th, 2024
669
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.epam.rd.qa.aggregation;
  2.  
  3. import java.math.BigDecimal;
  4. import java.math.RoundingMode;
  5.  
  6. public class BaseDeposit extends Deposit {
  7.     public BaseDeposit(BigDecimal amount, int period) {
  8.         super(amount, period);
  9.     }
  10.  
  11.     @Override
  12.     public BigDecimal income() {
  13.         BigDecimal totalIncome = BigDecimal.ZERO;
  14.         BigDecimal currentAmount = getAmount();
  15.         for (int i = 0; i < getPeriod(); i++) {
  16.             BigDecimal interestRate = BigDecimal.valueOf(0.05);
  17.             BigDecimal rawInterest = currentAmount.multiply(interestRate);
  18.             BigDecimal interest = rawInterest.setScale(2, RoundingMode.HALF_EVEN);
  19.  
  20.             totalIncome = totalIncome.add(interest);
  21.             currentAmount = currentAmount.add(interest);
  22.         }
  23.         return totalIncome;
  24.     }
  25.  
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement