Skip to content

Лаба 1 - #1

Open
Dan0nK wants to merge 3 commits into
mainfrom
dev
Open

Dan0nK wants to merge 3 commits into
mainfrom
dev

Conversation

@Dan0nK

@Dan0nK Dan0nK commented Feb 7, 2023

Copy link
Copy Markdown
Owner

No description provided.

Comment thread src/main/java/Main.java Outdated
{
System.out.println("Ошибка. Попробуйте ещё раз. Введите число > 1");
}
}

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

while(true)
{

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)
{

Не совсем джава-стиль. Вообще есть хороший хоткей, можно нажать Alt + Ctrl + L и студия красиво отформатирует весь код на экране

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

public static class 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 в классе Main. Лучше вынести Calculator в отдельный файл

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

void out(){
System.out.println("Добавленные товары:" + allNames);
System.out.println("Общая стоимость: " + allPrices + declension(allPrices));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Такие подряд идущие println можно объединить в один

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

void add(String name, double price) {
allNames = allNames + "\n" + name + " " + String.format("%.2f", price) + declension(price);
allPrices = allPrices + price;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно также написать allPrices += price;

public class CheckInput {
Scanner scanner = new Scanner(System.in);

int CheckCountPeople() {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

в Java принято называть методы camelCase'ом, т.е. с маленькой буквы

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