-
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), затем выбрать, какую часть кода хочешь изменить, и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).
src/main/java/Main.java
Outdated
|
|
||
| while(start) { | ||
| System.out.println("На сколько человек делим счет?"); | ||
| int numberPeople = 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.
src/main/java/Main.java
Outdated
| int numberPeople = scanner.nextInt(); | ||
|
|
||
| if ( numberPeople > 1 ) { | ||
| 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.
⏫ Сейчас здесь варнинг потому что все мтоды в классе Calculator статические, а значит для обращения к ним не требуется экземпляр класса. Поэтому если ты обратишься к нужному метод так: Calculator.calculator(numberPeople); - то варнинг уйдет.
src/main/java/Main.java
Outdated
| if ( numberPeople > 1 ) { | ||
| Calculator calculator = new Calculator(); | ||
| calculator.calculator( numberPeople ); | ||
| start = false; |
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) { ... }, а здесь вызвать break - этот вызов прерывает цикл и выходит из него.
src/main/java/Main.java
Outdated
| String list = "" ; | ||
| String endingRub = ""; | ||
| String endingSum = ""; | ||
| Double sumEach ; |
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
| DecimalFormat decimalFormat = new DecimalFormat( "#.##" ); | ||
|
|
||
|
|
||
| while (goodsNext) { |
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.
⏫ Тут варнинг, потому что всегда true и переменная никак не меняется. Поэтому можно просто здесь написатьwhile(true) и варнинг уйдет.
src/main/java/Main.java
Outdated
| Scanner scanner = new Scanner(System.in); | ||
| String nameGoods = scanner.nextLine(); | ||
|
|
||
| if (nameGoods.equalsIgnoreCase(finish)) { |
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
|
|
||
| decimalFormat.format(price); | ||
|
|
||
| list = list + " \n" + nameGoods + " – " + price + " рубл" + endingRub ; |
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
src/main/java/Main.java
Outdated
|
|
||
| int priceInt = (int)price; | ||
|
|
||
| if (priceInt == 11) { |
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.
Надо проверять последнюю или 2 последних цифры числа, в зависимости от ситуации, чтобы правильно определить склонение. Есть несколько случаев, которые нужно проверить, когда заканчивается на:
- 0
- 1
- 2-4
- 5-9
- и исключение, когда надо проверять, что заканчивается на 11-14
src/main/java/Main.java
Outdated
| } No newline at end of file | ||
| } | ||
|
|
||
| class 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.
Смотря какие варнинги. Которые я указал, лучше поправить, но на принятие работы это не повлияет. |
| break; | ||
| } | ||
| } | ||
| } else { |
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.
⏫ тут код по сути дублируется, поэтому можно не делать if, а просто вынести и оставить только код, который в первой ветке
price %= 100;
if (price == 11 || price == 12 || price == 13 || price == 14) {
ending = endingThree;
} else {
priceInt %= 10;
switch (priceInt) {
case 1:
ending = endingOne;
break;
case 2:
case 3:
case 4:
ending = endingTwo;
break;
default:
ending = endingThree;
break;
}
}
Этого должно хватить
Программа у меня запускается и отрабатывает, но там есть некоторое количество warning-ов. Не знаю, критично это или нет?