Skip to content

Спринт 2. Проектная работа 1 "Калькулятор счета". - #43

Open
Barsec13 wants to merge 2 commits into
Yandex-Practicum:masterfrom
Barsec13:master
Open

Barsec13 wants to merge 2 commits into
Yandex-Practicum:masterfrom
Barsec13:master

Conversation

@Barsec13

Copy link
Copy Markdown

No description provided.

double allPrice;
//Сохранение названия товаров и общей стоимости заказа
void addProduct(Product product){
allProduct = allProduct + "!" + product.nameProduct;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Если ! используется как некий разделитель, можно завести строковую или Char константу с ним. Тогда будет сразу в коде понятно, для чего добавляется, ниже будет понятно, почему проверяем символ на соответствие !, и уменьшится вероятность ошибки

if (ruble % 10 == 1){
endingRuble = "рубль";
}
else if (ruble % 10 == 2 || ruble % 10 == 3 || ruble % 10 == 4){

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ruble % 10 используется несколько раз, можно посчитать один раз и использовать дальше переменную. Ещё условие можно заменить на ... >= 2 && ... <=4

else if (ruble % 10 == 2 || ruble % 10 == 3 || ruble % 10 == 4){
endingRuble = "рубля";
}
else endingRuble = "рублей";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Вместо if-else можно использовать switch

Comment thread src/main/java/Main.java
static void checkQuantityPeople(){
while (true) {
//Проверка ввода пользователя на пустое значение или не целое число до его чтения
if (scanner.hasNext() && scanner.hasNextInt())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

По идее, можно ограничиться проверкой scanner.hasNextInt(), потому что если она даст true, то и scanner.hasNext() должен быть true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants