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
This repository was archived by the owner on Apr 14, 2025. It is now read-only.

Comments

Дополнил код#1

Open
PapaRimsky wants to merge 3 commits intomain from
dev
Open

Дополнил код #1
PapaRimsky wants to merge 3 commits intomain from
dev

Conversation

@PapaRimsky
Copy link
Owner

@PapaRimsky PapaRimsky commented Mar 13, 2023

Классы:
main-начало, создание объектов каждого класса и вывод
item-ввод данных товара с консоли
calculate-сложение
format-проверка на последнюю цифру в числе и преобразование числа

import java.util.Scanner;
public class Item {

Scanner scanner = new Scanner(System.in);
Copy link

@gusar-off gusar-off Mar 14, 2023

Choose a reason for hiding this comment

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

Лучше переиспользовать инстанс сканнера, а не создавать каждый раз новый, можно передать сюда в конструкторе

}
}
System.out.println("Итог - "+formatter.price(calculate.finalPrice));
System.out.print("Сумма с каждого - "+formatter.price(calculate.finalPrice/(float)countPerson)+" ");
Copy link

@gusar-off gusar-off Mar 14, 2023

Choose a reason for hiding this comment

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

В таких случаях для вывода лучше использовать System.out.printf, ему можно передать параметры, которые будут поставлены в строку.

public class Format {
String line="";
String ruble(float numb){
int i = (int)Math.floor(numb);
Copy link

@gusar-off gusar-off Mar 14, 2023

Choose a reason for hiding this comment

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

По сути здесь достаточно приведения к int, потому что оно делает тоже самое что и Math.floor, только еще и делает приведение типа

String ruble(float numb){
int i = (int)Math.floor(numb);
if(i<21){
compare(i);
Copy link

@gusar-off gusar-off Mar 14, 2023

Choose a reason for hiding this comment

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

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

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

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 によって変換されたページ (->オリジナル) /