From 5b38e26fbbd84469da766ea6cbf113b9cccd8380 Mon Sep 17 00:00:00 2001 From: Gyuzyal Date: Sat, 24 Dec 2022 20:40:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=D0=B9=20Code=20style?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/CalculateDeposit.java | 43 ++++++++++++++++++++++++++++++++++++++ src/calculate_deposit.java | 40 ----------------------------------- 2 files changed, 43 insertions(+), 40 deletions(-) create mode 100644 src/CalculateDeposit.java delete mode 100644 src/calculate_deposit.java diff --git a/src/CalculateDeposit.java b/src/CalculateDeposit.java new file mode 100644 index 00000000..71041a8f --- /dev/null +++ b/src/CalculateDeposit.java @@ -0,0 +1,43 @@ +import java.util.Scanner; + +public class CalculateDeposit { + + double calculateComplexPercent(double money, double yearRate, int period) { + double amountOfFunds = money * Math.pow((1 + yearRate / 12), 12 * period); + return accrualOfInterest(amountOfFunds, 2); + } + + double calculateSimplePercent(double money, double yearRate, int period) { + return accrualOfInterest(money + money * yearRate * period, 2); + } + + double accrualOfInterest(double sum, int bet) { + double percent = Math.pow(10, bet); + return Math.round(sum * percent) / percent; + } + + void calculateСontribution( ) { + int period; + int action; + double sumContributor = 0; + + Scanner scanner = new Scanner(System.in); + System.out.println("Введите сумму вклада в рублях:"); + int money = scanner.nextInt(); + System.out.println("Введите срок вклада в годах:"); + period = scanner.nextInt( ); + System.out.println("Выберите тип вклада, 1 - вклад с обычным процентом, 2 - вклад с капитализацией:"); + action = scanner.nextInt(); + + if (action == 1) { + sumContributor = calculateSimplePercent(money, 0.06, period); + } else if (action == 2) { + sumContributor = calculateComplexPercent(money, 0.06, period); + } + System.out.println("Результат вклада: " + money + " за " + period + " лет превратятся в " + sumContributor); + } + + public static void main(String[] args) { + new CalculateDeposit().calculateСontribution(); + } +} diff --git a/src/calculate_deposit.java b/src/calculate_deposit.java deleted file mode 100644 index 90164f11..00000000 --- a/src/calculate_deposit.java +++ /dev/null @@ -1,40 +0,0 @@ -import java.net.URI;import java.util.Scanner;import java.io.IOException; - -public class calculate_deposit -{ -double Calculate_Complex_Percent_Function(double a, double y,int d ) { - double pay = a * Math.pow((1 + y/ 12), 12 *d); - return rnd(pay, 2); - } double Calculate_Simple_Percent_Function(double doubleAmount,double double_year_rate, int deposit_period) { - return rnd(doubleAmount+doubleAmount * double_year_rate *deposit_period, 2); - } double rnd(double value - ,int places) { - double ScaLe= Math.pow - (10, places); - return Math.round(value*ScaLe) - /ScaLe; } - - void do_important_job( ) - { - int period, action ; - Scanner abcdef = new Scanner(System.in); System.out.println("Введите сумму вклада в рублях:") ; - int amount = abcdef.nextInt(); System.out.println("Введите срок вклада в годах:") ; - period = abcdef.nextInt( ); - System.out.println ( "Выберите тип вклада, 1 - вклад с обычным процентом, 2 - вклад с капитализацией:"); - action = abcdef.nextInt(); - double outDoubleVar = 0; - if (action ==1) outDoubleVar = Calculate_Simple_Percent_Function(amount, 0.06, period); - else if (action == 2) - { - outDoubleVar = Calculate_Complex_Percent_Function(amount, 0.06, period); } - System.out.println("Результат вклада: " + amount + " за " + period + " лет превратятся в " + outDoubleVar); - } -public static void main(String[] args) - { - new calculate_deposit().do_important_job(); -} - - - - -}