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