Skip to content

Проектная работа 1 - #1

Open
tasha-a wants to merge 2 commits into
mainfrom
dev
Open

tasha-a wants to merge 2 commits into
mainfrom
dev

Conversation

@tasha-a

@tasha-a tasha-a commented Apr 23, 2023

Copy link
Copy Markdown
Owner

Программа у меня запускается и отрабатывает, но там есть некоторое количество warning-ов. Не знаю, критично это или нет?

@SeveNChaK SeveNChaK left a comment

Copy link
Copy Markdown

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), затем выбрать, какую часть кода хочешь изменить, и выполнить команду. Среда разработки автоматически сделает нужные отступы и переносы (как она это делает можно изменить в настройках, но дефолтные значения вполне нормальные).

Comment thread src/main/java/Main.java Outdated

while(start) {
System.out.println("На сколько человек делим счет?");
int numberPeople = scanner.nextInt();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Не хватает проверки на ввод букв, сейчас приложение падает

Comment thread src/main/java/Main.java Outdated
int numberPeople = scanner.nextInt();

if ( numberPeople > 1 ) {
Calculator calculator = new Calculator();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ Сейчас здесь варнинг потому что все мтоды в классе Calculator статические, а значит для обращения к ним не требуется экземпляр класса. Поэтому если ты обратишься к нужному метод так: Calculator.calculator(numberPeople); - то варнинг уйдет.

Comment thread src/main/java/Main.java Outdated
if ( numberPeople > 1 ) {
Calculator calculator = new Calculator();
calculator.calculator( numberPeople );
start = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ Можно не заводить переменную, а просто сделать цикл while (true) { ... }, а здесь вызвать break - этот вызов прерывает цикл и выходит из него.

Comment thread src/main/java/Main.java Outdated
String list = "" ;
String endingRub = "";
String endingSum = "";
Double sumEach ;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ Переменная никак не используется

Comment thread src/main/java/Main.java Outdated
DecimalFormat decimalFormat = new DecimalFormat( "#.##" );


while (goodsNext) {

@SeveNChaK SeveNChaK Apr 24, 2023 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ Тут варнинг, потому что всегда true и переменная никак не меняется. Поэтому можно просто здесь написатьwhile(true) и варнинг уйдет.

Comment thread src/main/java/Main.java Outdated
Scanner scanner = new Scanner(System.in);
String nameGoods = scanner.nextLine();

if (nameGoods.equalsIgnoreCase(finish)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ Не хватает сообщения про ввод "завершить", сейчас не понятно когда это нужно вводить

Comment thread src/main/java/Main.java Outdated

decimalFormat.format(price);

list = list + " \n" + nameGoods + " – " + price + " рубл" + endingRub ;

@SeveNChaK SeveNChaK Apr 24, 2023 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⏫ Тут как раз варнинг про сложение строк. Так как String является неизменяемым объектом, то при каждом сложении строк создаются новые объекты, что расходует память. Для таких случаев лучше использовать StringBuilder

Comment thread src/main/java/Main.java Outdated

int priceInt = (int)price;

if (priceInt == 11) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ А если это не 11, но заканчивается на 11? Там тоже будет такое же окончание. А еще не хватает учета 12, 13 и 14.
Надо проверять последнюю или 2 последних цифры числа, в зависимости от ситуации, чтобы правильно определить склонение. Есть несколько случаев, которые нужно проверить, когда заканчивается на:

  • 0
  • 1
  • 2-4
  • 5-9
  • и исключение, когда надо проверять, что заканчивается на 11-14

Comment thread src/main/java/Main.java Outdated
} No newline at end of file
}

class Calculator {

@SeveNChaK SeveNChaK Apr 24, 2023 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Принято писать каждый класс в своем файле с таким же названием файла, что и у класса. Так что вынеси, пожалуйста, этот класс отдельно.

@SeveNChaK

SeveNChaK commented Apr 24, 2023 •

Copy link
Copy Markdown

Программа у меня запускается и отрабатывает, но там есть некоторое количество warning-ов. Не знаю, критично это или нет?

Смотря какие варнинги. Которые я указал, лучше поправить, но на принятие работы это не повлияет.

break;
}
}
} else {

Copy link
Copy Markdown

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;
                }
            }

Этого должно хватить

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.

2 participants