-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathDepositCalculator.java
More file actions
47 lines (35 loc) · 1.69 KB
/
DepositCalculator.java
File metadata and controls
47 lines (35 loc) · 1.69 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
40
41
42
43
44
45
46
47
import java.util.Scanner;
public class DepositCalculator {
private double calculateComplexPercent(double amount, double annualRate, int depositPeriod) {
double pay = amount * Math.pow((1 + annualRate / 12), 12 * depositPeriod);
return roundNumber(pay, 2);
}
private double calculateSimplePercent(double amount, double annualRate, int depositPeriod) {
return roundNumber(amount + amount * annualRate * depositPeriod, 2);
}
private double roundNumber(double value, int places) {
double scale = Math.pow(10, places);
return Math.round(value * scale) / scale;
}
public void calculateDepositValue() {
int period;
int action;
Scanner scanner = new Scanner(System.in);
System.out.println("Введите сумму вклада в рублях:");
int amount = scanner.nextInt();
System.out.println("Введите срок вклада в годах:");
period = scanner.nextInt();
System.out.println("Выберите тип вклада, 1 - вклад с обычным процентом, 2 - вклад с капитализацией:");
action = scanner.nextInt();
double resultAmount = 0;
if (action == 1) {
resultAmount = calculateSimplePercent(amount, 0.06, period);
} else if (action == 2) {
resultAmount = calculateComplexPercent(amount, 0.06, period);
}
System.out.println("Результат вклада: " + amount + " за " + period + " лет превратятся в " + resultAmount);
}
public static void main(String[] args) {
new DepositCalculator().calculateDepositValue();
}
}