Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Add dev branch#1

Open
Taras2023 wants to merge 3 commits intomain from
dev
Open

Add dev branch #1
Taras2023 wants to merge 3 commits intomain from
dev

Conversation

@Taras2023
Copy link
Owner

@Taras2023 Taras2023 commented Jan 15, 2023

No description provided.

Calculator(){
numberPeople();
addProduct();
totals();
Copy link

@gusar-off gusar-off Jan 17, 2023

Choose a reason for hiding this comment

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

Не очень правильно делать основную работу класса в конструкторе, он нужен для инициализации, передачи аргументов снаружи


while (true) {
System.out.println("На скольки человек необходимо разделить счет?");
number = scanner.nextInt();
Copy link

@gusar-off gusar-off Jan 17, 2023

Choose a reason for hiding this comment

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

⚠️ Если передать в этот момент произвольную строку программа завершит работу с исключением. Перед тем, как прочитать инт из сканнера, нужно сначала проверить возможно ли это при помощи соответствующего метода hasNextInt

System.out.println("Введите название товара");
this.product = scanner.next();
System.out.println("Введите цену товара");
this.price = scanner.nextFloat();
Copy link

@gusar-off gusar-off Jan 17, 2023

Choose a reason for hiding this comment

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

⚠️ Тут тоже самое, только hasNextFloat

else if (lastnumber==1)
rub = "рубль";
else
rub = "рубля";
Copy link

@gusar-off gusar-off Jan 17, 2023

Choose a reason for hiding this comment

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

⚠️Немного некорректно рассчитывается окончание. Получается если цена будет 112 рублей, метод вернет рубля. Правильный алгоритм звучит так - Проверить лежит ли остаток от деления на 100 в интервале от 11 до 14 включительно, если да, то возвращаем рублей, если нет, то берем остаток от деления на 10 и проверяем - если 1, то рубль, 2-4 то рубля, в остальных случаях - рублей. То есть нужно во-первых проверять именно остаток от деления, во-вторых учесть, что числа заканчивающиеся на 11-12-13-14 и заканчивающиеся на 1-2-3-4, будут иметь разные окончания

AddProduct nomenclature = new AddProduct();
amount += nomenclature.price;
products = products +"\n"+ nomenclature.product;
System.out.println("Вы хотите добавить еще один товар?");
Copy link

@gusar-off gusar-off Jan 17, 2023

Choose a reason for hiding this comment

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

С точки зрения пользователя было бы удобнее здесь уточнить, что нужно ввести в консоль, чтобы завершить добавление товаров

public void totals(){

System.out.println("Добавленные товары: \n" + products);
System.out.println("Стоимость товаров: " + amount);//String.format("%.2f",amount));
Copy link

@gusar-off gusar-off Jan 17, 2023

Choose a reason for hiding this comment

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

Закомментированный код лучше убрать.

2. Исправил ввод цены
3. Исправил ввод количества человек
4. Исправил окончание слова рубль

} else {
System.out.println("Введите положительное число");
scanner = new Scanner(System.in);
Copy link

@gusar-off gusar-off Jan 22, 2023

Choose a reason for hiding this comment

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

Тут и выше можно не создавать каждый раз новый инстанс класса Scanner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@gusar-off gusar-off gusar-off left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /