Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 64 additions & 5 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,67 @@
import java.util.Scanner;

public class Main {

public static void main(String[] args) {
// ваш код начнется здесь
// вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
System.out.println("Привет Мир");
}
}

int peopleNumber = PeopleCounter.countPeople();

System.out.println("Введите название блюда.");
String foodName;
double foodPrice;
double priceSum = 0;
String foodList = "Добавленные блюда: ";

while (true) {
Scanner foodScanner = new Scanner(System.in);
foodName = foodScanner.nextLine();
if (foodName.equalsIgnoreCase("Завершить")) {
break;
} else if (foodName.equals("")) {
System.out.println("Вы ничего не ввели. Необходимо ввести название товара.");
continue;
}

System.out.println("Введите стоимость блюда в формате ХХ,ХХ");

while (true) {
Scanner priceScanner = new Scanner(System.in);
if (priceScanner.hasNextDouble()) {
foodPrice = priceScanner.nextDouble();
if (foodPrice < 0) {
System.out.println("Стоимость блюда не может быть меньше 0, введите верное значение");
} else {
System.out.println("Блюдо " + foodName + " за " + foodPrice + " руб. добавлено." + "\n" + "Добавьте еще одно блюдо или введите 'Завершить', чтобы узнать, сколько вы должны заплатить.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

И тут тоже

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

почитаю тоже

break;
}
} else {
System.out.println("Возможно, вы ошиблись. Введите стоимость блюда в формате ХХ,ХХ");
}
}
foodList = String.format("%s\n%s", foodList, foodName);
priceSum += foodPrice;
}

double eachPay = priceSum / peopleNumber;
String totalResult = "Общая сумма - %.2f";
String personalResult = "Каждый должен заплатить %.2f";
String ruble;

if ((int) eachPay % 100 >= 10 && (int) eachPay % 100 <= 20) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

На самом деле будет достаточно проверить интервал от 11 до 14 включительно

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

боюсь трогать, пусть работает)

ruble = "рублей";
} else {
switch ((int) (eachPay % 10)) {
case 1:
ruble = "рубль";
break;
case 2:
case 3:
case 4:
ruble = "рубля";
break;
default:
ruble = "рублей";
}}
System.out.println(foodList + "\n" + String.format(totalResult, priceSum) + " руб." + "\n" + String.format(personalResult, eachPay) + " " + ruble + ".");
}
}
23 changes: 23 additions & 0 deletions src/main/java/PeopleCounter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import java.util.Scanner;

public class PeopleCounter {

public static int countPeople (){
System.out.println("Приветствую! На сколько человек поделим счет?");
int peopleNumber;
while (true) {
Scanner peopleScanner = new Scanner(System.in);
if (peopleScanner.hasNextInt()) {
peopleNumber = peopleScanner.nextInt();
if (peopleNumber <= 1) {
System.out.println("Не вижу смысла в таких подсчетах. Возможно, вы ошиблись. Попробуем еще раз?");
} else {
break;
}
} else {
System.out.println("Это не целое число, возможно, вы ошиблись. Попробуем еще раз?");
}
}
return peopleNumber;
}
}