-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathDepositCalculator.java
More file actions
39 lines (34 loc) · 1.63 KB
/
DepositCalculator.java
File metadata and controls
39 lines (34 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import java.util.Scanner;
public class DepositCalculator {
double findComplexPercent(double amount, double yearRate, int depositPeriod) {
double totalAmount = amount * Math.pow((1 + yearRate / 12), 12 * depositPeriod);
return getRounded(totalAmount, 2);
}
double findSimplePercent(double amount, double yearRate, int depositPeriod) {
double totalAmount = amount + amount * yearRate * depositPeriod;
return getRounded(totalAmount, 2);
}
double getRounded(double value, int places) {
double scale = Math.pow(10, places);
return Math.round(value * scale) / scale;
}
void getResultDeposit() {
Scanner scanner = new Scanner(System.in);
System.out.println("Введите сумму вклада в рублях:");
int amount = scanner.nextInt();
System.out.println("Введите срок вклада в годах:");
int period = scanner.nextInt();
System.out.println("Выберите тип вклада, 1 - вклад с обычным процентом, 2 - вклад с капитализацией:");
int userInput = scanner.nextInt();
double result = 0;
if (userInput == 1) {
result = findSimplePercent(amount, 0.06, period);
} else if (userInput == 2) {
result = findComplexPercent(amount, 0.06, period);
}
System.out.println("Результат вклада: " + amount + " за " + period + " лет превратятся в " + result);
}
public static void main(String[] args) {
new DepositCalculator().getResultDeposit();
}
}