Skip to content

консольное приложение №1#1

Open
Nadezhda-Gurova wants to merge 3 commits intomainfrom
dev
Open

консольное приложение №1#1
Nadezhda-Gurova wants to merge 3 commits intomainfrom
dev

Conversation

@Nadezhda-Gurova
Copy link
Copy Markdown
Owner

Версия 1

Comment thread src/main/java/Main.java Outdated
import java.util.Scanner;

public class Main {
static class Product {
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
}


static void inputProduct(Scanner scanner, Basket basket) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ Сканер можно не передавать в качестве параметра везде, а просто вынести в поле класса Main

Comment thread src/main/java/Main.java Outdated
String name = scanner.nextLine();
System.out.println("Введите стоимость товара");
double price = Double.parseDouble(scanner.nextLine());
basket.add(new Product(name, price));
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
char lastChar = rub.charAt(indexOf - 1);
if (lastChar == '1') {
return "рубль";
} else if ("234".indexOf(lastChar) != -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.

⏫ Такой indexOf можно заменить на contains.
⚠️ Также для этих цифр склонение указано неверно - 2, 3, 4 рублЯ. И обрати внимание в какую ветку будут попадать такие числа, как 11-14 или 111-114. Кажется, что что-то будет не так. Стоит внимательнее обработать и проверить все варианты. Подсказка: надо бращать на последнюю или 2 последних цифры, в зависимости от ситуации

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

String inclineRubEnding(String rub) {
int indexOf = rub.indexOf(".");
char lastChar = rub.charAt(indexOf - 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.

⏫ Для нахождения нужных последних цифр лучше использовать остаток от деления. Например, 21 % 10 даст нам цифру 1, а 111 % 100 даст нам последние 2 цифры

Comment thread src/main/java/Main.java Outdated
try {
num = Integer.parseInt(scanner.nextLine());
} catch (NumberFormatException e) {

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/Basket.java

class Basket {
List<String> products = new ArrayList<>();
double sum = 0.0;
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/Basket.java
List<String> products = new ArrayList<>();
double sum = 0.0;

String inclineRubleEnding(int ruble) {
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/Basket.java
for (String product : products) {
System.out.println(product);
}
System.out.println(String.format(Locale.US, "%.2f", sum / numberOfPersons)
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/Basket.java
+ " " + inclineRubleEnding((int) Math.floor(sum / numberOfPersons)));
}

void add(Product product) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ В целом сюда можно просто сразу передать имя и цену товара и избавиться таким образов от класса Product. Просто больше этот класс нигде не используется, а создается и сразу же из него берутся поля, поэтому заворчивать их в этот класс - мало пользы

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