Skip to content
Open
Show file tree
Hide file tree
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
43 changes: 43 additions & 0 deletions src/DepositCalculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 round(pay, 2);
}

double calculateSimplePercent(double amount, double yearRate, int depositPeriod) {
return round(amount + amount * yearRate * depositPeriod, 2);
}

double round(double value, int places) {
double scale = Math.pow(10, places); //предлагаю переименовать в lowCase
return Math.round(value * scale) / scale; //предлагаю переименовать в lowCase
}

void calculateDeposit() {
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 out = 0;

if (action == 1) {
out = calculateSimplePercent(amount, 0.06, period);
} else if (action == 2) {
out = calculateComplexPercent(amount, 0.06, period);
}

System.out.println("Результат вклада: " + amount + " за " + period + " лет превратятся в " + out);
}

public static void main(String[] args) {
new DepositCalculator().calculateDeposit();
}
}
40 changes: 0 additions & 40 deletions src/calculate_deposit.java

This file was deleted.