-
Notifications
You must be signed in to change notification settings - Fork 220
ПР по домашнему заданию по результатам 2 спринта#122
ПР по домашнему заданию по результатам 2 спринта #122AshZoom wants to merge 19 commits intoYandex-Practicum:master from
Conversation
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.
- Название переменной sTart не совсем понятно. Лучше делать наименования более содержательными. Тема названий, да и не только хорошо раскрывается во 2 главе книги Роберта Мартина "Чистый код". Также на хабре есть краткий конспект книги: https://habr.com/ru/post/485118/
- Также все поля и методы класса помечены static, это означает, что для работы с ними не нужно создавать экземпляр класса, а можно вызвать его напрямую из класса, например
People.countPeople()
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.
Исправлено
"Также на хабре есть краткий конспект книги: https://habr.com/ru/post/485118/" @azat Nabiullin: Спасибо за рекомендацию!
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.
Можно People.numberOfPeople вместо sTart.numberOfPeople
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.
Можно использовать метод printf:
System.out.printf("Итого: "+"%.2f"+ "руб.%n",Products.total);
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.
Исправлено.
@azat Nabiullin:
Я правильно понимаю разницу между методом println и printf (см/ ниже)?
Используем метод System.out.printf,т.к. хотим просто вывести строку в консоль. Если бы мы хотели получить отформатированную строку для дальнейшего использования в коде, используем System.out.println.
src/main/java/People.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.
Можно весь этот блок с if (numberOfPeople <= 1) просто перенести в блок else предыдущего if
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/Products.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.
В Java принята конвенция, по которой все имена переменных называются camelCase'ом, то есть с маленькой буквы. Почитать про конвенции названий можно здесь:
https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
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.
Исправлено.
@azat Nabiullin: Спасибо за рекомендацию!
src/main/java/Products.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.
Лучше избегать названий типа name1, price2 и т.д. Здесь можно назвать просто name.
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/Products.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.
Можно использовать короткую конструкцию total += j вместо total=total+j
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/Products.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.
Метод возвращает boolean, но при этом возвращаемый тип нигде не используется, а просто присваивается значение переменной finishOfList и в цикле while проверяется.
Так что в этом методе можно ничего не возвращать и сделать void, а возвращаемое значение убрать
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.
Исправлено.
...спринта А.Шмаков)
...спринта А.Шмаков)
Init commit
src/main/java/Products.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.
В методах, не возвращающих результат (void) return в конце метода не нужен. return нужен для возвращения результата, а смысл в void в том, что он результат не возвращает.
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.
Можно влю эту if-else конструкцию упростить до такой:
finishOfList= !add.equalsIgnoreCase("завершить");
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/Products.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.
Можно обойтись и без o=10/0, а просто выводить сообщение об ошибочном вводе. break в if нет так что и так будет повторный запрос ввода.
Кстати, когда надо искусственно вызвать ошибку, можно использовать конструкцию throw new Exception("Текст ошибки");
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.
Исправлено. Я торопился сдать работу, чтобы успеть приступить к проектной работе No2, т.к. запутался как правильно оформлять Pull Request. Опыта в программировании нет и поэтому я решил задачу"в лоб" через костыли (деление на ноль).
Спасибо! Информацию по вызову ошибку записал для дальнейшего использования/
Направляю на проверку домашнее задание по результатам 2 спринта