-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Первая версия программы #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <module type="JAVA_MODULE" version="4"> | ||
| <component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
| <exclude-output /> | ||
| <content url="file://$MODULE_DIR$"> | ||
| <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
| </content> | ||
| <orderEntry type="inheritedJdk" /> | ||
| <orderEntry type="sourceFolder" forTests="false" /> | ||
| </component> | ||
| </module> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); | ||
| } | ||
| } | ||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
С 27 по 39 желательно выделить операции в отдельные логические блоки, иначе текст сливается и глаз хуже цепляется за отдельные элементы при первом прочтении. В данном случае это небольшой метод, но в достаточно сложных методах и если ты возвращаешься к этим методами спустя долгое время (> пол года) будет сложно читать и добавлять новый функционал в этот метод
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Спасибо за замечание, я исправлю)