Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Calculator#101

Open
harhanov wants to merge 6 commits intoYandex-Practicum:master from
harhanov:master
Open

Calculator #101
harhanov wants to merge 6 commits intoYandex-Practicum:master from
harhanov:master

Conversation

@harhanov
Copy link

@harhanov harhanov commented Oct 29, 2022

No description provided.

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

@MagicUnderHood MagicUnderHood Oct 30, 2022

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);
Copy link

@MagicUnderHood MagicUnderHood Oct 30, 2022

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

Reviewers

1 more reviewer

@MagicUnderHood MagicUnderHood MagicUnderHood left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /