import java.util.Locale; import java.util.Scanner; public class Calculator { private Scanner scanner = new Scanner(System.in); private String dishes = "ÐобавленнÑе ÑоваÑÑ:\n "; private double summary = 0; void addDishes() { while (true) { System.out.println("ÐведиÑе название пÑодÑкÑа."); dishes += scanner.next() + " \n"; System.out.println("ТепеÑÑ Ð²Ð²ÐµÐ´Ð¸Ñе его ÑÑоимоÑÑÑ Ð² ÑоÑмаÑе [ÑÑб.коп.]."); while (!scanner.hasNextDouble()) { scanner.next(); System.out.println("ÐÑибка, введиÑе коÑÑекÑное ÑиÑло."); } while (true) { double i = scanner.nextDouble(); if (i <= 0) { System.out.println("ÐведиÑе коÑÑекÑнÑÑ ÑÑоимоÑÑÑ Ð¿ÑодÑкÑа."); } else { summary += i; break; } } System.out.println("УÑÐ¿ÐµÑ ! \nХоÑиÑе ли добавиÑÑ ÐµÑе пÑодÑкÑ?"); String answer = scanner.next(); if (answer.equalsIgnoreCase("завеÑÑиÑÑ")) { break; } } } void showResult(int guests) { double result = summary / guests; String rubleTitle = rubleCase(result); System.out.println(dishes); System.out.println(String.format("%.2f", result) + " " + rubleTitle); } private String rubleCase(double money) { int floorMoney = (int) Math.floor(money); int lastDigit = floorMoney % 10; if (lastDigit == 1) { return "ÑÑÐ±Ð»Ñ "; } else if (lastDigit == 2 || lastDigit == 3 || lastDigit == 4) { return "ÑÑблÑ"; } else { return "ÑÑблей "; } } }