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 LongDeposit extends Deposit {
- public LongDeposit(BigDecimal amount, int period) {
- super(amount, period);
- }
- @Override
- public BigDecimal income() {
- BigDecimal totalIncome = BigDecimal.ZERO;
- BigDecimal currentAmount = getAmount();
- for (int i = 1; i <= getPeriod(); i++) {
- BigDecimal rawInterest;
- BigDecimal interest;
- if (i > 6) {
- rawInterest = currentAmount.multiply(BigDecimal.valueOf(0.15));
- } else {
- rawInterest = BigDecimal.ZERO; // No interest for the first 6 months
- }
- 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