Skip to content

Dev - #1

Open
AntaOtk wants to merge 3 commits into
masterfrom
dev
Open

Dev#1
AntaOtk wants to merge 3 commits into
masterfrom
dev

Conversation

@AntaOtk

@AntaOtk AntaOtk commented Nov 25, 2022

Copy link
Copy Markdown
Owner
  1. В описании задачи не говорилось о том, что количество людей может быть не целым числом, в связи с этим не стала делать на это проверку при вводе.
  2. Не поняла из условия, как запрашивать товар, поэтому реализовала через 2 запроса. и в случае ошибки прошу вводить товар заново с 0.

Comment thread src/main/java/Main.java Outdated
int n;
while (true) {
System.out.println("На скольких человек необходимо разделить счёт");
n = scanner.nextInt();

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() или try-catch

Comment thread src/main/java/ProductList.java Outdated
boolean err = false;
if (add2.length() > 3) {
for (int i = 0; i < add2.length(); i++) {
if ((!Character.isDigit(add2.charAt(i))) && (i != add2.length() - 3)) {

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.hasNextFloat() и потом scanner.nextFloat()

Comment thread src/main/java/ProductList.java Outdated
System.out.println("введите имя");
add1 = scanner.nextLine();
System.out.println("введите стоимость");
add2 = scanner.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.

Лучше давать более понятные имена, например, people, goodName, cost

Comment thread src/main/java/ProductList.java Outdated
}
if ((add2.charAt(add2.length() - 3) == '.') && !err) {
productsList.add(new Product(add1, Float.parseFloat(add2)));
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/ProductList.java Outdated
System.out.println("введите стоимость");
add2 = scanner.nextLine();
boolean err = false;
if (add2.length() > 3) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Из-за этого условия стоимость просто целым числом, например, 24, не принимается

Comment thread src/main/java/ProductList.java Outdated
String end = "завершить";
String add1;
String add2;
for (; ; ) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно использовать while(true)

Comment thread src/main/java/Main.java Outdated
System.out.println("Добавленные товары:");
products.writeNameList();
int rub = (int) output;
if ((rub % 10 == 1) && (rub / 10 != 1)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Выражение rub % 10 считается несколько раз, можно посчитать его один раз, записать в переменную и использовать ее
Перед проверкой rub / 10 != 1 лучше взять rub%100, то есть отбросить все цифры, кроме последних двух, чтобы проверять также и 119, 212 и т.д.

Comment thread src/main/java/Main.java Outdated
} else if ((rub % 10 >= 2) && (rub % 10 <= 4) && (rub / 10 != 1)) {
System.out.println(String.format("%.2f", output) + " рубля");
} else {
System.out.println(String.format("%.2f", output) + " рублей");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Код System.out.println(String.format("%.2f", output) + " рублей"); повторяется в каждой ветке, кроме слова рубль, лучше код вынести после if-else, оставив в нем только определение слова

@AntaOtk

AntaOtk commented Nov 29, 2022

Copy link
Copy Markdown
Owner Author

@MagicUnderHood , спасибо большое за ревью. поправила код согласно советам.

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