Skip to content

Березин Максим: проектная работа №1 - первый pull request#126

Closed
MBerezin wants to merge 18 commits intoYandex-Practicum:masterfrom
MBerezin:master
Closed

Березин Максим: проектная работа №1 - первый pull request#126
MBerezin wants to merge 18 commits intoYandex-Practicum:masterfrom
MBerezin:master

Conversation

@MBerezin
Copy link
Copy Markdown

No description provided.

Locale.setDefault(Locale.US);

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

Choose a reason for hiding this comment

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

Можно объединить инициализацию переменной с ее объявлением

int peopleCounter = countPeople(scanner);
Calculator calculator = new Calculator(peopleCounter);

double productPrice;
String productName;
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.

Допускается один отступ, а здесь 3

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Между 4-ой и 8-ой строкой?


productName = scanner.next();

if (productName.equalsIgnoreCase("ЗАВЕРШИТЬ")){
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

"ЗАВЕРШИТЬ" лучше вынести в статическую константу

}

private String getCurrencyWriting(double price){
int roundedPrice = (int)Math.floor(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.

Math.floor округляет до целого в меньшую сторону, а приведение к int отбрасывает дробную часть. То есть это по сути эквивалентные операции, но с разными типами в результате. Поэтому нет смысла делать и то и другое. Лучше сделать только Math.floor потому что это более явно.

return String.format("%,.2f", price);
}

private String getCurrencyWriting(double 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.

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

- delete redundant indents
- unite declaration and initialisation some variables
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.

3 participants