Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Мимика Максим. Задание 02_12 #8965

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions 02-java-types/task12/src/com/example/task12/Task12.java
Original file line number Diff line number Diff line change
@@ -1,29 +1,21 @@
package com.example.task12;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class Task12 {

public static BigDecimal benefit(BigDecimal sum, BigDecimal percent) {

// TODO раскомментируйте и исправьте код

// Считаем проценты за год

/*
for (int i = 1; i <= 12; i++) {
sum += sum * percent;
}
return sum;
*/

return BigDecimal.ZERO;
return sum.multiply(percent.add(BigDecimal.valueOf(1)).pow(12))
.setScale(9, RoundingMode.HALF_UP);
}

public static void main(String[] args) {
// 500 руб. на счете
BigDecimal sum = new BigDecimal(500).setScale(9, RoundingMode.HALF_UP);

BigDecimal sum = new BigDecimal(500).setScale(9, BigDecimal.ROUND_HALF_UP); // 500 руб. на счете
BigDecimal percent = new BigDecimal(0.00000001f).setScale(9, BigDecimal.ROUND_HALF_UP); // 0.000001% ежемесячно
// 0.000001% ежемесячно
BigDecimal percent = new BigDecimal(0.00000001f).setScale(9, RoundingMode.HALF_UP);

sum = benefit(sum, percent);

Expand Down