-
Notifications
You must be signed in to change notification settings - Fork 0
Дополнил код #1
base: main
Are you sure you want to change the base?
Дополнил код #1
Conversation
src/main/java/Item.java
Outdated
| import java.util.Scanner; | ||
| public class Item { | ||
|
|
||
| Scanner scanner = new Scanner(System.in); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Лучше переиспользовать инстанс сканнера, а не создавать каждый раз новый, можно передать сюда в конструкторе
src/main/java/Main.java
Outdated
| } | ||
| } | ||
| System.out.println("Итог - "+formatter.price(calculate.finalPrice)); | ||
| System.out.print("Сумма с каждого - "+formatter.price(calculate.finalPrice/(float)countPerson)+" "); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
В таких случаях для вывода лучше использовать System.out.printf, ему можно передать параметры, которые будут поставлены в строку.
src/main/java/Format.java
Outdated
| public class Format { | ||
| String line=""; | ||
| String ruble(float numb){ | ||
| int i = (int)Math.floor(numb); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
По сути здесь достаточно приведения к int, потому что оно делает тоже самое что и Math.floor, только еще и делает приведение типа
src/main/java/Format.java
Outdated
| String ruble(float numb){ | ||
| int i = (int)Math.floor(numb); | ||
| if(i<21){ | ||
| compare(i); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Классы:
main-начало, создание объектов каждого класса и вывод
item-ввод данных товара с консоли
calculate-сложение
format-проверка на последнюю цифру в числе и преобразование числа