import java.util.Random; import java.util.Scanner; // dev branch for Y.Practicum public class Main { static CountPersons countPersons = new CountPersons(); static int persons = 0; static double sum = 0; public static void main(String[] args) { // Ð²Ð°Ñ ÐºÐ¾Ð´ наÑнеÑÑÑ Ð·Ð´ÐµÑÑ // Ð²Ñ Ð½Ðµ Ð´Ð¾Ð»Ð¶Ð½Ñ Ð¾Ð³ÑаниÑиваÑÑÑÑ ÑолÑко клаÑÑом Main и можеÑе ÑоздаваÑÑ Ñвои клаÑÑÑ Ð¿Ð¾ Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ð¾ÑÑи countPersons.quantityOfPersons(); addProduct(); finish(); } public static class CountPersons { void quantityOfPersons() { Scanner scanner = new Scanner(System.in); System.out.println("СколÑко Ð²Ð°Ñ Ñеловек?"); while (true) { if (scanner.hasNextInt()) { persons = scanner.nextInt(); if (persons == 1) { System.out.println("ÐÑ Ð¾Ð´Ð¸Ð½, Ð½ÐµÑ ÑмÑÑла делиÑÑ."); } else if (persons < 1) { System.out.println("ÐевеÑное знаÑение менÑÑе 1"); } else if (persons > 1) { break; } else { System.out.println("ÐÑ Ð²Ð²ÐµÐ»Ð¸ не ÑиÑло"); scanner.nextLine(); } } } } } public static void addProduct() { Scanner scanner = new Scanner(System.in); double price = 0; String productList = "ÐобавленнÑе ÑоваÑÑ: \n"; String product = null; System.out.println("напиÑиÑе блÑдо"); while ((product = scanner.nextLine()) != null) { if (product.equalsIgnoreCase("ÐавеÑÑиÑÑ")) { System.out.println(productList); String str2 = String.format("ÐбÑÐ°Ñ ÑÑмма ÑоваÑов ÑоÑÑавила: %.2f", sum); System.out.println(str2); break; } System.out.println("ÑколÑко ÑÑÐ¾Ð¸Ñ Ð±Ð»Ñдо?"); while (true) { if (scanner.hasNextDouble()) { price = scanner.nextDouble(); if (price < 0) { System.out.println("ÐведÑÐ½Ð½Ð°Ñ ÑÑмма менÑÑе 0"); } else if (price >= 0) { sum += price; productList += product + "\n"; String str = String.format("%s ÑÑоимоÑÑÑÑ %.2f добавлено. СÑмма: %.2f", product, price, sum); System.out.println(str); System.out.println("напиÑиÑе блÑдо"); break; } else { System.out.println("Ðведено не ÑиÑло"); scanner.nextLine(); } } } scanner.nextLine(); } } public static void finish() { double total = sum/persons; int num1 = (int) (total); String result = null; if (total % 100 > 4 && total % 100 < 21) { result = "ÑÑблей"; } else if (total % 10 == 1) { result = "ÑÑблÑ"; } else if (total % 10 > 1 && total % 10 < 5) { result = "ÑÑблÑ"; } int num2 = persons; String result2 = null; if (num2 % 100 > 4 && num2 % 100 < 21) { result2 = "Ñеловека"; } else if (num2 % 10 > 1 && num2 % 10 < 5) { result2 = "Ñеловек"; String str = String.format("ÐÐ°Ñ %d %s, С каждого по %.2f %s", persons, result2, total, result); System.out.println(str); } } }