-
Notifications
You must be signed in to change notification settings - Fork 0
Пулл реквес первой проектной работы #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), затем выбрать, какую часть кода хочешь изменить, и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).
src/main/java/Calkulater.java
Outdated
| double summ = 0; | ||
| double money = 0; | ||
| int ost; | ||
| double ostl; |
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.
⏫ Все поля можно сделать приватными
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
| int person; | ||
|
|
||
|
|
||
| while (!sc.hasNextInt()) { |
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.
sc.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.
Изменил, теперь должно быть все норм)
| } | ||
|
|
||
|
|
||
| while (true) { |
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.
⏫ Думаю весь этот цикл можно объединить в один предыдущий и тогда можно решить проблему с вводом букв
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/Calkulater.java
Outdated
| cost = sc.nextDouble(); | ||
| if (cost <= 0 ) { | ||
| System.out.println("Не корректное цифра");} | ||
| // else if (!sc.hasNextDouble()) {System.out.println("Буквы нельзя в стоимсть вводить");} |
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.
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/Calkulater.java
Outdated
| } | ||
|
|
||
| summ = summ + cost; | ||
| nameAll = nameAll + "\n" + name; |
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
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/Calkulater.java
Outdated
| nameAll = nameAll + "\n" + name; | ||
|
|
||
| String messageTemplate1 = "Вы успешно добавили товар на общую сумму %.2f руб., добавьте товар еще, или наберите слово Завершить"; | ||
| System.out.println(String.format(messageTemplate1, summ)); |
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(messageTemplate1, summ);
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/Calkulater.java
Outdated
|
|
||
| money = summ / person; | ||
|
|
||
| ostl = money % 10f; |
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.
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.
Заменил значение на 20, и добавил в свич вариантов до 19ти
src/main/java/Ostatok.java
Outdated
| case 9: rubli ="Рублей"; break; | ||
| } | ||
| String messageTemplate = "Вы заказали %s, скидываемся по %.2f %s."; | ||
| System.out.println(String.format(messageTemplate, nameAll, money, rubli)); |
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.
⏫ Тут тоже можно подсократить, как писал уже выше
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.
сократил, пришлось немного помудрить с переносом строки
|
|
||
| switch (ost){ | ||
| case 0: rubli ="Рублей"; break; | ||
| case 1: rubli ="Рубль"; break; |
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.
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.
добавил до 19ти
| double money = 0; | ||
| int ost; | ||
| double ostl; | ||
| private double summ = 0; |
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/Calkulater.java
Outdated
|
|
||
| ostl = money % 10f; | ||
| ost = (int)ostl; | ||
| padegD = moneyPerPerson % 20f; |
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.
= 302, получаем 151 рублей.
И чтобы не делать большой свитч и все работало корретно, стоит просто получить 2 последние цифры числа (остаток от деления на 100), затем проверить, что это >=11 и <=14 (тогда пишем рублей), и если не попадет в это условие, то проверить уже остаток от деления на 10.
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.
Исправил, проверил выводом всех значений.
| public class Ostatok { | ||
| void ostat (int padeg, double moneyPerPerson, String nameOfDishesAll){ | ||
| void ostat (double moneyPerPerson, String nameOfDishesAll){ | ||
| String rubli = new String(); |
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 rubli = "";
|
|
||
| padegD = moneyPerPerson % 100f; | ||
| if (padegD > 14) {padegD = padegD % 10f;} | ||
| padeg = (int) padegD; |
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 padeg = ((int) moneyPerPerson) % 100;
if (padeg > 14) {
padeg = padeg % 10;
}
Вроде все работает...