-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathDepositCalculator.java
More file actions
46 lines (35 loc) · 1.62 KB
/
DepositCalculator.java
File metadata and controls
46 lines (35 loc) · 1.62 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
import java.util.Scanner;
public class DepositCalculator {
double calculateComplexPercent(double amount, double yearRate, int depositPeriod) {
double pay = amount * Math.pow((1 + yearRate / 12), 12 * depositPeriod);
return squaring(pay, 2);
}
double calculateSimplePercent(double amount, double yearRate, int depositPeriod) {
return squaring(amount + amount * yearRate * depositPeriod, 2);
}
double squaring(double value, int places) {
double scale = Math.pow(10, places);
return Math.round(value * scale)/ scale;
}
void calculatePersents() {
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 moneySum = 0;
if (action == 1) {
moneySum = calculateSimplePercent(amount, 0.06, period);
} else if (action == 2) {
moneySum = calculateComplexPercent(amount, 0.06, period);
}
System.out.println("Результат вклада: " + amount + " за " + period + " лет превратятся в " + moneySum);
}
public static void main(String[] args) {
new DepositCalculator().calculatePersents();
}
}