Skip to content

dz - #85

Open
Sssenju wants to merge 4 commits into
Yandex-Practicum:devfrom
Sssenju:dev
Open

dz#85
Sssenju wants to merge 4 commits into
Yandex-Practicum:devfrom
Sssenju:dev

Conversation

@Sssenju

@Sssenju Sssenju commented Jun 22, 2023

Copy link
Copy Markdown

No description provided.

@kgornostaeva

Copy link
Copy Markdown

🍏 Лучше именовать коммиты более явным образом, например, так: "Домашнее задание 2 спринт. Первая попытка". Или просто "Спринт 2". Это поможет ориентироваться и тебе, и ревьюерам, когда ты будешь работать над большим проектом

Comment thread src/main/java/Main.java
int guests = Integer.parseInt(myObj.nextLine());
if (guests <= 1) {
System.out.println("Некореректное число гостей");
return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 При ошибочном вводе пользователя сразу выбрасывает из программы. Было бы круто дать ему возможность еще раз ввести данные. Для этого тебе нужно обернуть запросы на ввод в цикл

Comment thread src/main/java/Main.java Outdated

int guests = Integer.parseInt(myObj.nextLine());
if (guests <= 1) {
System.out.println("Некореректное число гостей");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Опечатка в слове "Некорректное"

Comment thread src/main/java/Main.java Outdated
public static void main(String[] args) {
System.out.println("Hello world!");
Scanner myObj = new Scanner(System.in);
System.out.println("Введите число гостей");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Было бы классно подсказать пользователю, какое число от него ожидается (например, добавить "от 2-х человек")

Comment thread src/main/java/Main.java Outdated
Scanner myObj = new Scanner(System.in);
System.out.println("Введите число гостей");

int guests = Integer.parseInt(myObj.nextLine());

@kgornostaeva kgornostaeva Jun 22, 2023 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Можно использовать nextInt, под капотом он сделает всю работу по парсингу:

int guests = myObj.nextInt();

⚠️ В любом случае нужно этот вызов либо обернуть в try-catch, либо перед этим проверить, что пользователь ввел число, с помощью myObj.hasNextInt()

Comment thread src/main/java/Main.java Outdated
System.out.println("Введите название товара: ");
String itemName = myObj.nextLine();
System.out.println("Введите стоимость товара: ");
double itemPrice = Double.parseDouble(myObj.nextLine());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Можно использовать nextDouble, под капотом он сделает всю работу по парсингу:

int guests = myObj.nextDouble();
⚠️ В любом случае нужно этот вызов либо обернуть в try-catch, либо перед этим проверить, что пользователь ввел число с помощью myObj.hasNextDouble()

Comment thread src/main/java/Main.java Outdated
while (true) {
System.out.println("Введите название товара: ");
String itemName = myObj.nextLine();
System.out.println("Введите стоимость товара: ");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Хорошо бы подсказать пользователю, в каком формате ему вводить данные

Comment thread src/main/java/Main.java Outdated
return;
}
System.out.println("Добавлен товар " + itemName + "," + itemPrice);
System.out.println("Хотите ли добавить еще товар?");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Здесь тоже круто было бы, подсказать, как он должен выйти из цикла вопросов и завершить подсчет

Comment thread src/main/java/Main.java Outdated

String UserInput = myObj.nextLine();
System.out.println(UserInput.toLowerCase());
if (UserInput.toLowerCase().equals("завершить")) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Можно заменить на вот этот метод, работать будет так же.

Suggested change
if (UserInput.toLowerCase().equals("завершить")) {
if (UserInput.equalsIgnoreCase("завершить")) {

Comment thread src/main/java/Main.java
int rubles = (int) amount;
if (rubles % 10 == 1 && rubles % 100 != 11) {
return "рубль";
} else if (rubles % 10 >= 2 && rubles % 10 <= 4 && (rubles % 100 < 10 || rubles % 100 >= 20)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Здесь у тебя несколько раз происходит операция вычисления остатка от деления на 10 и на 100. Можно рассчитать их заранее, а затем использовать в блоке if-else.
Возможно, после такого преобразования тебе удобно будет применить вместо if-else оператор switch.
https://javarush.com/groups/posts/operator-switch-v-java

Comment thread src/main/java/Main.java

while (true) {
System.out.println("Введите название товара: ");
String itemName = myObj.nextLine();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Сейчас пользователь может ввести вместо названия товара одни пробелы. Было бы классно исключить такой ввод. Для этого можно использовать метод строки trim, а потом проверить с помощью isEmpty.

Comment thread src/main/java/Main.java Outdated
int guests;
while (true) {
System.out.println("Введите число гостей (от 2-х человек): ");
guests = Integer.parseInt(myObj.nextLine());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Если пользователь введет буквы или Enter вместо цифр, то приложение падает. Используй myObj.hasNextInt(), чтобы проверить ввел ли пользователь цифры или нет, а затем myObj.nextInt(), чтобы получить введенное значение

Comment thread src/main/java/Main.java Outdated
myObj.nextLine();
userInput = myObj.nextLine().toLowerCase();

} while (!userInput.equals("завершить"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🍏 Чтобы заранее не приводить к строчным буквам, можно использовать следующий метод

Suggested change
} while (!userInput.equals("завершить"));
} while (!userInput.equalsIgnoreCase("завершить"));

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