-
Notifications
You must be signed in to change notification settings - Fork 0
Консольное приложение №1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
SeveNChaK
left a comment
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.
В файлах код прыгает, отступы не одинаковые - рекомендую использовать встроенные форматтер. Если ты программируешь в IDE от JetBrains, то можешь пройтись по всем файлам и нажать комбинацию (Windows: Shift + Ctrl + Alt + L, MacOS: Shift + Option + Command + L), затем выбрать, какую часть кода хочешь изменить, и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| 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.
⏫ Переменная не используется, ее можно удалить
| product.nameRequest1(); | ||
| product.checkingThePrice(); | ||
| product.nameRequest2(); | ||
| String transfer = "\n"; |
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.
⏫ Тоже не используется
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| String name1; |
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.
⏫ Неинформативное название, рекомендую назвать, например, productNames
| public class Calculator { | ||
| String name1; | ||
| String name2; | ||
| double price1; |
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.
⏫ Неинформативное название, рекомендую назвать, например, priceSum
|
|
||
| public class Calculator { | ||
| String name1; | ||
| String name2; |
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.
⏫ Можно не делать полем класса, так как переменная используется только внутри метода nameRequest2, поэтмоу ее можно объявлять там внутри
| String name1; | ||
| String name2; | ||
| double price1; | ||
| double price2; |
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.
⏫ Можно не делать полем класса, так как переменная используется только внутри метода checkingThePrice, поэтмоу ее можно объявлять там внутри
| if (name2.equalsIgnoreCase("завершить")){ | ||
| break; | ||
| } else { | ||
| name1 = name1 + ", " + transfer + name2; |
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.
⏫ Так как String является неизменяемым объектом, то при каждом сложении строк создаются новые объекты, что расходует память. Для таких случаев лучше использовать StringBuilder
| void checkingThePrice() { | ||
| while (true) { | ||
| System.out.println("Введите стоимость товара"); | ||
| price2 = scanner.nextDouble(); |
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.
scanner.hasNextDouble() для проверки, перед чтением nextDouble().
|
|
||
| while (true) { | ||
| System.out.println("На скольких человек необходимо разделить счет?"); | ||
| countPersons = scanner.nextInt(); |
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.
scanner.hasNextInt()
|
|
||
| void formatter() { | ||
| Person count = new Person(); | ||
| Calculator calculator = new Calculator(); |
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.
Person и Calculator, в них нет посчитанных ранее тобой данных, поэтому склоняется не правильно.
Лучше нужное число передать параметром на вход метода, а результат вернуть сразу из метода, а не записывать в переменную: String formatter(double priceOnEachPerson) { ... }.
Полученный double можно привести к int: int priceInt = (int) double;.
А потом уже проверять priceInt твоим условием, но в switch надо поправить на switch (priceInt % 10)
No description provided.