Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

create Calculator#1

Open
dencharski wants to merge 2 commits intomain from
mydev
Open

create Calculator #1
dencharski wants to merge 2 commits intomain from
mydev

Conversation

@dencharski
Copy link
Owner

@dencharski dencharski commented Dec 7, 2022

No description provided.

System.out.println("На сколько человек делим счет?");

try {
String s = scanner.next();
Copy link

@gusar-off gusar-off Dec 8, 2022

Choose a reason for hiding this comment

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

У Scanner есть удобный метод hasNextInt, можно сразу узнать без дополнительных проверок возможно ли интерпретировать строку как int

System.out.println("Ошибка! " + errorString);
}

static void onDestroy() {
Copy link

@gusar-off gusar-off Dec 8, 2022

Choose a reason for hiding this comment

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

Совсем не обязательно пытаться уничтожить объекты самостоятельно, после завершения программы, сборщик мусора будет удалять эти объекты, а их зануление по факту ничего не делает.

}
priceForOnePeople = finalPrice / peoples;

return ("Продукт " + product.productName + " по цене " + product.productPrice + " добавлен.");
Copy link

@gusar-off gusar-off Dec 8, 2022

Choose a reason for hiding this comment

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

В таких случаях для вывода лучше использовать System.out.printf, ему можно передать параметры, которые будут поставлены в строку.

private String convertPriceToString(double price) {
String stringPrice = String.format("%.2f", price);
String zeroEnd = "0";
if (stringPrice.endsWith(zeroEnd)) {
Copy link

@gusar-off gusar-off Dec 8, 2022
edited
Loading

Choose a reason for hiding this comment

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

Немного некорректно рассчитывается окончание. Получается если цена будет 14 рублей, метод вернет рубля. Правильный алгоритм звучит так - Округлить double до целых, проверить лежит ли остаток от деления на 100 в интервале от 11 до 14 включительно, если да, то окончание "рублей", если нет, то берем остаток от деления на 10 и проверяем: если 1 - рубль, если 2-4 - рубля, остальные случаи - рублей. То есть нужно во-первых проверять именно остаток от деления, во-вторых учесть, что числа заканчивающиеся на 11-12-13-14 и заканчивающиеся на 1-2-3-4, будут иметь разные окончания

} else {
allProductNames = allProductNames + ", \n" + product.productName;
}
priceForOnePeople = finalPrice / peoples;
Copy link

@gusar-off gusar-off Dec 8, 2022

Choose a reason for hiding this comment

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

Можно посчитать это значение один раз - при выводе значения в getPriceForOnePeople

-deleted fun onDestroy().
-in fun addProduct() change return String to String.format().
-changed the calculation of the endings of the word "рубль".
-the variable "priceForOnePeople" is counted once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@gusar-off gusar-off gusar-off left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /