import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); scanner.useDelimiter("\\n"); StringBuilder menu = new StringBuilder(); System.out.println("Ðа ÑколÑко Ñеловек ÑазделиÑÑ Ð²Ð°Ñ ÑÑеÑ?"); int friends = countFriend(scanner); int processAdd; double total = 0; do { System.out.println("УкажиÑе название блÑда:"); String dish = scanner.next(); while(dish.isEmpty()) { System.out.println("Ðазвание блÑда не должно бÑÑÑ Ð¿ÑÑÑÑм."); dish = scanner.next(); } menu.append(dish).append("\n"); System.out.println("УкажиÑе ÑÑоимоÑÑÑ Ð±Ð»Ñда:"); total = total + checkPrice(scanner); System.out.println("ÐлÑдо добавлено в ÑпиÑок"); System.out.println("ÐелаеÑе добавиÑÑ ÐµÑе одно блÑдо? (УкажиÑе \"ÐавеÑÑиÑÑ\" Ð´Ð»Ñ Ð·Ð°Ð²ÐµÑÑÐµÐ½Ð¸Ñ Ð¿ÑоÑеÑÑа или введиÑе лÑбÑе ÑимволÑ, Ð´Ð»Ñ Ð¿ÑодолжениÑ)"); processAdd = enterCommand(scanner); } while(processAdd == 0); //ÐÑводим калÑкÑлÑÑÐ¾Ñ double calculate = total / (double)friends; String bill = String.format("%.2f", calculate); String sum = String.format("%.2f", total); Ruble rubleSum = new Ruble(); Ruble rubleBill = new Ruble(); String changeRubleSum = rubleSum.recieveRuble(total); String changeRubleBill = rubleBill.recieveRuble(calculate); String resultMenu = menu.toString(); System.out.println("ÐобавленнÑе блÑда:"); System.out.println(resultMenu); System.out.println("СÑоимоÑÑÑ Ð·Ð°ÐºÐ°Ð·Ð°:"); System.out.println(sum + changeRubleSum); System.out.println("ÐолиÑеÑÑво гоÑÑей:"); System.out.println(friends); System.out.println("СÑоимоÑÑÑ Ñека на каждого:"); System.out.println(bill + changeRubleBill); } //ÐбÑабаÑÑваем вÑвод колиÑеÑÑва дÑÑзей public static int countFriend(Scanner scanner) { while (true) { if(scanner.hasNextInt()) { int number = scanner.nextInt(); if(number <= 1) {System.out.println("УкажиÑе ÑиÑло болÑÑе 1.");} else {return number;} } else { System.out.println("ÐÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ð¾ ÑказаÑÑ Ñелое ÑиÑло."); scanner.next(); } } } //ÐбÑабаÑÑваем вÑвод ÑÑÐ¼Ð¼Ñ public static double checkPrice (Scanner scanner) { while (true) { if(scanner.hasNextDouble()) { double price = scanner.nextDouble(); if(price <= 0) {System.out.println("УкажиÑе ÑиÑло болÑÑе 0.");} else {return price;} } else { System.out.println("ÐÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ð¾ ÑказаÑÑ ÑиÑло."); scanner.next(); } } } //РеÑаем, завеÑÑаÑÑ Ð»Ð¸ нам добавление блÑд или пÑодолжаÑÑ public static int enterCommand(Scanner scanner) { String dishAdd = scanner.next(); int command; if(dishAdd.equalsIgnoreCase("ÐавеÑÑиÑÑ")) { command = 1; } else { command = 0; } return command; } }