-
Notifications
You must be signed in to change notification settings - Fork 0
Comments
Conversation
src/main/java/Calculator.java
Outdated
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.
Список продуктов может быть final, так как нигде не изменяет своего значения (то есть не присваивается новый список)
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.
Также можно не указвать явно тип два раза, то есть если слева уже указан , то справа это можно опустить, чтобы сделать код более лакончиным
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.
По идее эта проверка всегда будет true, так как в программе еще до этого проверяется, что количество больше нуля. Но в целом имеет место быть)
src/main/java/Main.java
Outdated
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.
Можно смело удалять неиспользуемые строки, они только ухудшают восприятие кода)
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.
Все, что в этом else, можно было бы вынести в отдельный метод, чтобы немного разгрузить main, а также чтобы не было сильной вложенности кода. (сначала в if, потом в while, это создает лишние отступы)
src/main/java/Main.java
Outdated
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.
Здесь можно было бы дописать текст, что программа ждет ввода стоимости продукта, это было бы немного более юзер френдли
src/main/java/Main.java
Outdated
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.
Этот объект нигде не используется, так как ниже строчкой создается точно такой же новый
src/main/java/Main.java
Outdated
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.
Условие i != '.' всегда будет true, так как оно проверяется на один if выше. i равное точке никогда не дойдет до этого ифа, можно смело удалять. Аналогичная история и с !Character.isDigit(i). Поэтому этот блок можно сделать просто через else, без if
src/main/java/Main.java
Outdated
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.
Здесь можно пропустить else:
if (countPoint > 1) {
rez = false;
}
return rez;
src/main/java/Product.java
Outdated
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.
Можно не создавать геттеров и сеттеров, если они не требуются извне. Из всех здесь и ниже, понадобился лишь getPrice
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.
Необязательно писать инициализаторы явно. По умолчанию double имет значение 0, строка и объект null
src/main/java/Main.java
Outdated
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.
В этом месте стоило бы выполнять проверку с помощью метода scanner.nextInt(), который возвращает булевое значение в зависимости от того, сможет ли он введенное число распознать как инт или нет. Либо использовать блок try-catch. Тогда не будет такого краша:
Это Pull Request задачи 2 спринта.