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

Задание к спринту No2#1

Open
MetelikovSergey wants to merge 3 commits intomain from
dev
Open

Задание к спринту No2 #1
MetelikovSergey wants to merge 3 commits intomain from
dev

Conversation

@MetelikovSergey
Copy link
Owner

@MetelikovSergey MetelikovSergey commented Feb 14, 2023

No description provided.


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

@gusar-off gusar-off Feb 14, 2023

Choose a reason for hiding this comment

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

⚠️ Если передать в этот момент произвольную строку программа завершит работу с исключением. Перед тем, как прочитать int из сканнера, нужно сначала проверить возможно ли это при помощи соответствующего метода hasNextInt


public class Calculator {
public static void calculete(int countGuest) {
Scanner scanner = new Scanner(System.in);
Copy link

@gusar-off gusar-off Feb 14, 2023

Choose a reason for hiding this comment

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

Лучшее переиспользовать инстанс Scanner, а не создавать каждый раз новый.

} else {
product.nameProduct += name + "\n ";
System.out.println("Введите стоимость товара (цифрой)");
product.priceProduct += scanner.nextDouble();
Copy link

@gusar-off gusar-off Feb 14, 2023

Choose a reason for hiding this comment

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

Тоже самое как с hasNextInt только hasNextDouble

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@gusar-off gusar-off gusar-off 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 によって変換されたページ (->オリジナル) /