import java.util.Scanner; public class Main { private static Calculator calculator; private static Scanner scanner; public static void main(String[] args) { scanner = new Scanner(System.in); int numberOfPeople = askNumberOfPeople(); calculator = new Calculator(numberOfPeople); askProductAndPrice(); showResult(); } private static int askNumberOfPeople() { System.out.println("Ðного ваÑ?"); int numberOfPeople; while (true) { if (scanner.hasNextInt()) { numberOfPeople = scanner.nextInt(); scanner.nextLine(); if (numberOfPeople > 1) { return numberOfPeople; } System.out.println("ÐведиÑе коÑÑекÑное колиÑеÑÑво лÑдей (>1)"); } else { System.out.println("ÐведиÑе ÑиÑло >1"); } } } public static void askProductAndPrice() { while (true) { System.out.println("ЧÑо кÑÑаÑÑ Ð¸Ð·Ð²Ð¾Ð»Ð¸Ñе?"); String product = scanner.nextLine(); System.out.println("Че поÑем?"); double price = askPrice(); calculator.addProduct(product, price); System.out.println("Я вÑе запомнил!"); System.out.println("ÐÑе заказÑваÑÑ Ð±ÑдеÑе? ÐÑли неÑ, введиÑе \"завеÑÑиÑÑ\" "); String input = scanner.nextLine(); if ("завеÑÑиÑÑ".equalsIgnoreCase(input)) { break; } } } private static double askPrice() { while (true) { double price; if (scanner.hasNextDouble()) { price = scanner.nextDouble(); scanner.nextLine(); if (price <= 0) { System.out.println("ÐеÑплаÑнÑй ÑÑÑ ÑолÑко в мÑÑеловке! ÐекоÑÑекÑÐ½Ð°Ñ Ñена"); } else { return price; } } else { scanner.nextLine(); System.out.println("ÐведиÑе ÑÐµÐ½Ñ Ð² ÑоÑмаÑе ÑÑбли.копейки"); } } } private static void showResult() { System.out.println("ÐобавленнÑе ÑоваÑÑ:"); System.out.println(calculator.getProducts()); double personalBill = calculator.getPersonalBill(); double first = Math.floor(personalBill / 10) % 10; double second = Math.floor(personalBill) % 10; String rubName; if (second == 1 && first != 1) { rubName = "ÑÑблÑ"; } else if (second >= 2 && second <= 4 && first != 1) { rubName = "ÑÑблÑ"; } else { rubName = "ÑÑблей"; } System.out.println(String.format("С ноÑа : %.2f %s", personalBill, rubName)); } }