Skip to content
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

code review #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions m1-t12-code-style.iml
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>
57 changes: 57 additions & 0 deletions src/DepositCalculate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import java.util.Scanner;

public class DepositCalculate {
double calculateComplexPercent(double amount, double yearRate, int depositPeriod) {
double pay = amount * Math.pow((1 + yearRate / 12), 12 * depositPeriod);

return roundNumber(pay, 2);
}

double calculateSimplePercent(double amount,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

аргумент метода лучше в одну строчку, если они помещаются в 120 символов

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Принято

double yearRate, int depositPeriod) {

return roundNumber(amount + amount

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут тоже думаю не стоит переносить

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Аналогично, принято

* yearRate * depositPeriod, 2);
}

double roundNumber(double value, int power) {
double scale = Math.pow(10, power);

return Math.round(value * scale) / scale;
}

void calculateProfitDeposit() {
int period;
int action;
int amount;

Scanner scanner = new Scanner(System.in);

System.out.println("Введите сумму вклада в рублях:");
amount = scanner.nextInt();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

на мой взгляд приятнее читать код, когда написано int amount = scanner.nextInt(); Сразу видишь какой тип, глазами не бегаешь на верх. Тут, наверное, дело вкуса.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ну да, кому как. Мне, например, удобнее так, но услышал тебя, спасибо.


System.out.println("Введите срок вклада в годах:");
period = scanner.nextInt();

System.out.println("Выберите тип вклада, " +
"1 - вклад с обычным процентом, " +
"2 - вклад с капитализацией:");
action = scanner.nextInt();

double sumDeposit = 0;

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

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

public static void main(String[] args) {
new DepositCalculate().calculateProfitDeposit();
}
}