Skip to content

Conversation

@harhanov
Copy link

No description provided.

Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("Введите количество гостей.");
int number = scanner.nextInt();

Choose a reason for hiding this comment

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

Пользователь может ввести на вопрос про количество человек вместо целого числа строку, и приложение упадет. Для стоимости товаров ты обрабатываешь такую ситуацию, стоит добавить обработку и для количества людей, чтобы приложение не падало/ Можешь использовать try-catch или hasNextInt


public class Calculator {

static Scanner scanner = new Scanner(System.in);

Choose a reason for hiding this comment

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

Все поля и методы класса лучше делать не статическими (убрать static у всех), в этом нет необходимости. А при вызове метода в Main создавать объект класса:

        Calculator calc = new Calculator();
        calc.printResult(numberOfGuests);

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.

3 participants