Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.epam.rd.qa.aggregation;
- import java.math.BigDecimal;
- import java.math.RoundingMode;
- public class BaseDeposit extends Deposit {
- public BaseDeposit(BigDecimal amount, int period) {
- super(amount, period);
- }
- @Override
- public BigDecimal income() {
- BigDecimal totalIncome = BigDecimal.ZERO;
- BigDecimal currentAmount = getAmount();
- for (int i = 0; i < getPeriod(); i++) {
- BigDecimal interestRate = BigDecimal.valueOf(0.05);
- BigDecimal rawInterest = currentAmount.multiply(interestRate);
- BigDecimal interest = rawInterest.setScale(2, RoundingMode.HALF_EVEN);
- totalIncome = totalIncome.add(interest);
- currentAmount = currentAmount.add(interest);
- }
- return totalIncome;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement