diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 00000000..26d33521 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..dda71418 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..28678352 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..35eb1ddf --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/m1-t12-code-style.iml b/m1-t12-code-style.iml new file mode 100644 index 00000000..c90834f2 --- /dev/null +++ b/m1-t12-code-style.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/out/production/m1-t12-code-style/DepositCalculator.class b/out/production/m1-t12-code-style/DepositCalculator.class new file mode 100644 index 00000000..36dc817d Binary files /dev/null and b/out/production/m1-t12-code-style/DepositCalculator.class differ diff --git a/src/DepositCalculator.java b/src/DepositCalculator.java new file mode 100644 index 00000000..9d9f9946 --- /dev/null +++ b/src/DepositCalculator.java @@ -0,0 +1,45 @@ +import java.util.Scanner; + +public class DepositCalculator { + + double calculateComplexPercent(double depositAmount, double yearRate, int depositPeriod) { + double amount = depositAmount * Math.pow((1 + yearRate / 12), 12 * depositPeriod); + + return calculateAmountWithPercents(amount, 2); + } + + double calculateSimplePercent(double depositAmount, double yearRate, int depositPeriod) { + return calculateAmountWithPercents(depositAmount + depositAmount * yearRate * depositPeriod, 2); + } + + double calculateAmountWithPercents(double amount, int power) { + return Math.round(amount * Math.pow(10, power)) / Math.pow(10, power); + } + + void depositCalculation() { + int depositPeriod; + int command; + int depositAmount; + double amountWithPercents = 0; + double yearRate = 0.06; + Scanner scanner = new Scanner(System.in); + + System.out.println("Введите сумму вклада в рублях:"); + depositAmount = scanner.nextInt(); + System.out.println("Введите срок вклада в годах:"); + depositPeriod = scanner.nextInt(); + System.out.println("Выберите тип вклада, 1 - вклад с обычным процентом, 2 - вклад с капитализацией:"); + command = scanner.nextInt(); + if (command == 1) { + amountWithPercents = calculateSimplePercent(depositAmount, yearRate, depositPeriod); + } else if (command == 2) { + amountWithPercents = calculateComplexPercent(depositAmount, yearRate, depositPeriod); + } + System.out.print("Результат вклада: " + depositAmount + " за " + depositPeriod); + System.out.print(" лет превратятся в " + amountWithPercents); + } + + public static void main(String[] args) { + new DepositCalculator().depositCalculation(); + } +} \ No newline at end of file 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(); -} - - - - -}