Skip to content

Conversation

@NatalyaManzha
Copy link
Owner

1 попытка сдачи консольного приложения

@AleksandrIlinskii
Copy link

Программа крашится, если на этапе ввода количества человек ввести не число
image

System.out.println("Итого: " + String.format("%.2f", result) + " " + rubl + ";\nС каждого по: " + String.format("%.2f", resultPerPerson) + " " + rubl1 + ".");
}

String chooseTheCorrectCase(double x) { // метод для определения правильного падежа слова "рубль"

Choose a reason for hiding this comment

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

х - неинформативное название переменной, нужно называть так, чтобы оно отображало суть, что в ней лежит

String name;
double price;

public String checkName(String x) {

Choose a reason for hiding this comment

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

Тут тоже не понятно, что такое х

public String checkName(String x) {
while (true) {
Scanner scanner = new Scanner(System.in);
x = scanner.nextLine();

Choose a reason for hiding this comment

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

Зачем ты передаешь какой-то х, но потом ему присваиваешь значение введенной строки?

Scanner scanner = new Scanner(System.in);
if (!scanner.hasNextDouble()) System.out.println("Ошибка ввода. Введите цену товара в формате \"рубли,копейки\""); // если ввод текста вместо числа или "." вместо ","
else {
x = scanner.nextDouble();

Choose a reason for hiding this comment

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

Тут та же ситуация

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