import java.util.InputMismatchException; import java.util.Scanner; public class Calculator { static void calculate(int people) { String food = ""; double price = 0.0; while (true) { System.out.println("ХоÑиÑе еÑе добавиÑÑ ÑоваÑ?, еÑли да Ñо ÐведиÑе название ÑоваÑа" + "\nÐÐ»Ñ Ð·Ð°Ð²ÐµÑÑÐµÐ½Ð¸Ñ Ð²Ð²ÐµÐ´Ð¸Ñе 'ÐавеÑÑиÑÑ'"); Scanner scanner = new Scanner(System.in); String inputFood = scanner.next(); if (inputFood.equalsIgnoreCase("ÐавеÑÑиÑÑ")) { break; } else { food = food + inputFood + "\n"; price = price + price(); } } int rouble = (int) Math.round(price); System.out.println("ÐобавленнÑе ÑоваÑÑ:\n" + food); //String.join String message = "ÐаждÑй Ñеловек должен заплаÑиÑÑ %.2f" + " " + declination(rouble); System.out.println(String.format(message, (price / people))); } static double price() { while (true) { System.out.println("ÐведиÑе ÑÑоимоÑÑÑ Ð² ÑоÑмаÑе: 'ÑÑбли.копейки' [10,45, 11,40]"); double inputPrice = 0; try { Scanner scanner = new Scanner(System.in); inputPrice = scanner.nextDouble(); if (inputPrice <= 0){ System.out.println("ÐевеÑное знаÑение"); } else { return inputPrice; } } catch (InputMismatchException e) { System.out.println("ÐевеÑное знаÑение"); } } } private static String declination(int rouble) { switch (rouble % 10) { case 1: return "ÑÑблÑ"; case 2: case 3: case 4: return "ÑÑблÑ"; default: return "ÑÑблей"; } } }