From 63532ee6143420ddc89b7776e904fc27acc564d1 Mon Sep 17 00:00:00 2001 From: KonstantinKopylov Date: Sun, 9 Apr 2023 15:27:13 +0600 Subject: [PATCH 1/3] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D1=81=D0=BE=D0=B3=D0=BB=D0=B0=D1=81=D0=BD=D0=BE=20CodeStyle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 ++ .idea/misc.xml | 6 +++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ m1-t12-code-style.iml | 11 +++++ .../m1-t12-code-style/DepositCalculator.class | Bin 0 -> 2509 bytes src/DepositCalculator.java | 45 ++++++++++++++++++ src/calculate_deposit.java | 40 ---------------- 8 files changed, 79 insertions(+), 40 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 m1-t12-code-style.iml create mode 100644 out/production/m1-t12-code-style/DepositCalculator.class create mode 100644 src/DepositCalculator.java delete mode 100644 src/calculate_deposit.java 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..0319d5d5 --- /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 0000000000000000000000000000000000000000..1ee0acd49a317f44ba61893f80c69fed0aea7fce GIT binary patch literal 2509 zcmaJ@TUQfT7~KcR#V}lq;UmsSfXqEKoqcnif^TiYQ_VN5a;lL?hKi%VHc zyOwMD)JNa?)*>yJ0^)n0CcmTqq3u31Aw)w<);i~W-#Opj-|d{?&%f8V0G!2a0ByM7 z9gI-oUjT!+7(fdyc?UaOm3PpcoxLF+hWFqTj08}PPvz>eAJG7=;4`Ti^<&JBtKJL0 ztljwQar>G?x+aI~L4u6?@VOK&$YH{VTLRv5x}jSG0+o@j34y91b4nAa8`TZ%YA!XY zWyaOXBsIZNGp;5l)Qm3Wg0jk*(X#^kMu)YunboZ!H5tz(Rm;ru3pDY(BWXisDxK6G zT-P#j&9KNB86J*y4RfKU%$(E+3jR4w&D>NilGRMPc(l;XDQ-vUUs|0LXe@%pbO~C- zR5C=G8aKzuFvB<^!;-)=t0r><^kiu#qu4grO{3s5y+{{mylULyhJcU94MWSw(C(?T zYERD6lRYt4$b0u_@2XYCjElD%yIZm;F%?d5R(hx{XZ)85QK3RAysZ`h06Tci-qKjhXcdn5lm z|G3YGxPmEY3cka%!0B?BhxV4eUIt?SMl}HmA@J0Gk$*q(eTOe zu@Vhk3=`v3{#ky(eogz$u>FPrTlpu9<29q$vNw;0Pn8?3GnO|F(IVqovsdZH6VA)_ zAAJgr;;@1a92Tg*WSUmi%Bblv&6+W%vUOg}_@OJfhXfN_RtNI*=v<%j`TZ**V%un&B#IsfNXi(-etDhr7z}mJfz34exEoPP%nt)=X%H>*vCa@S>ZUIUnf1choc! zxwL>1l~;Z!sb;epIesdQynx|$!DZE$N^02-*Ra3bjS|gUhU0T-ZI|PvuYlVw{iU%L zAov_4W4fjF`;ZejTo&JMz6rGd|2e$J4?&yrdGSKX2ZZB6$~~L~XHWMk#49c;5auWk z0hKfZ6!!oQ;eASwH-;K%d>?-PfY#2st`I8Bc)il#nORsvRifA1-Rxa~=T~mKkO9u* zL5ScI_Cu~|T7+%I2k3ODS`p!@(%J1ow`1eO5$e3u@zxgTXDCbhU}tAnqQSF}i2oPs z9)2+cC9J_BYp}=~EV2gSvQ}e8n~oZLn?y^(|E^*n3V&!ENch zl=f{)1GT-L163~(>~38MA=I{l#$M0Q2p#aeL|swW)a#*DYg@Bt9nAoZW%(-+=GaHC zfd-boiS=s6es<3xjuF=D1pDX=J?&)+4Dj?A%a4KaKqTP>i>bn_R z1S2@bRRs|~#%Zo9$uY@Z_=s8U<#>j<@bJGSkhkI=f_r^v5kmM-&4#GQ9@_O5DiI}) z?5Ua!wA^0B{?Q{VXx-`IS|{ZZwn#TgjyR4rx&{oepN4)?onu$?al?7a6?FVQ=KwV( QvPd)R8_qew5CvlY0#mq~a{vGU literal 0 HcmV?d00001 diff --git a/src/DepositCalculator.java b/src/DepositCalculator.java new file mode 100644 index 00000000..cf6f904f --- /dev/null +++ b/src/DepositCalculator.java @@ -0,0 +1,45 @@ +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 roundToTenth(pay); + } + double calculateSimplePercent(double amount, double yearRate, int depositPeriod) { + double pay = amount + amount * yearRate * depositPeriod; + return roundToTenth(pay); + } + double roundToTenth(double value) { + double scale = Math.pow(10, 2); + return Math.round(value * scale) / scale; + } + + void calculationDeposit() { + int amount; + int period; + int action; + Scanner scanner = new Scanner(System.in); + + System.out.println("Введите сумму вклада в рублях:"); + amount = scanner.nextInt(); + System.out.println("Введите срок вклада в годах:") ; + period = scanner.nextInt( ); + System.out.println("Выберите тип вклада, 1 - вклад с обычным процентом, 2 - вклад с капитализацией:"); + action = scanner.nextInt(); + + double depositAmount = 0; + if (action == 1) { + depositAmount = calculateSimplePercent(amount, 0.06, period); + } else if (action == 2) { + depositAmount = calculateComplexPercent(amount, 0.06, period); + } + + System.out.println("Результат вклада: " + amount + " за " + period + " лет превратятся в " + depositAmount); + } + public static void main(String[] args) { + DepositCalculator depositCalculator = new DepositCalculator(); + + depositCalculator.calculationDeposit(); + } + +} 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(); -} - - - - -} From 416bf510af17a7b5da0f187969caeacaa370754e Mon Sep 17 00:00:00 2001 From: KonstantinKopylov Date: Sun, 9 Apr 2023 15:29:29 +0600 Subject: [PATCH 2/3] =?UTF-8?q?=D0=97=D0=B0=D0=B1=D1=8B=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D0=B0=D0=B2=D0=B8=D1=82=D1=8C=20=D0=BE=D1=82?= =?UTF-8?q?=D1=81=D1=83=D1=82=D0=BF=D1=8B:)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DepositCalculator.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/DepositCalculator.java b/src/DepositCalculator.java index cf6f904f..0324490a 100644 --- a/src/DepositCalculator.java +++ b/src/DepositCalculator.java @@ -1,14 +1,17 @@ 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 roundToTenth(pay); } + double calculateSimplePercent(double amount, double yearRate, int depositPeriod) { double pay = amount + amount * yearRate * depositPeriod; return roundToTenth(pay); } + double roundToTenth(double value) { double scale = Math.pow(10, 2); return Math.round(value * scale) / scale; @@ -36,6 +39,7 @@ void calculationDeposit() { System.out.println("Результат вклада: " + amount + " за " + period + " лет превратятся в " + depositAmount); } + public static void main(String[] args) { DepositCalculator depositCalculator = new DepositCalculator(); From de444e25f6c9ccb550ce04a6b29214de3266aa1e Mon Sep 17 00:00:00 2001 From: Serge Date: Sun, 9 Apr 2023 20:33:33 +0300 Subject: [PATCH 3/3] Update DepositCalculator.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Исправил обьявление локальных переменных из след соображений: Переменные определяются по мере надобности Локальные переменные не обязательно должны определятся в начале блока или метода. Вместо этого, он определяются как можно ближе к месту их первого использования, чтобы уменьшить область действия переменной. Локальные переменные как правило сразу инициализируются. --- src/DepositCalculator.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/DepositCalculator.java b/src/DepositCalculator.java index 0324490a..bb2ba31e 100644 --- a/src/DepositCalculator.java +++ b/src/DepositCalculator.java @@ -18,17 +18,16 @@ public class DepositCalculator { } void calculationDeposit() { - int amount; - int period; - int action; Scanner scanner = new Scanner(System.in); System.out.println("Введите сумму вклада в рублях:"); - amount = scanner.nextInt(); + int amount = scanner.nextInt(); + System.out.println("Введите срок вклада в годах:") ; - period = scanner.nextInt( ); + int period = scanner.nextInt( ); + System.out.println("Выберите тип вклада, 1 - вклад с обычным процентом, 2 - вклад с капитализацией:"); - action = scanner.nextInt(); + int action = scanner.nextInt(); double depositAmount = 0; if (action == 1) { @@ -42,7 +41,6 @@ void calculationDeposit() { public static void main(String[] args) { DepositCalculator depositCalculator = new DepositCalculator(); - depositCalculator.calculationDeposit(); }