import java.util.InputMismatchException; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Formatter formatter = new Formatter(); while (true) { System.out.println("Ðа ÑколÑÐºÐ¸Ñ Ñеловек ÑазделиÑÑ ÑÑÑÑ?"); try { int persons = scanner.nextInt(); scanner.nextLine(); if (persons < 1) System.out.println("ÐÑибка: некоÑÑекÑное ÑиÑло полÑзоваÑелей."); else if (persons == 1) System.out.println("ÐÑибка: делиÑÑ Ð½Ð¸Ñего не ÑÑебÑеÑÑÑ."); else { System.out.println("УÑÐ¿ÐµÑ : коÑÑекÑное ÑиÑло полÑзоваÑелей, можеÑе воÑполÑзоваÑÑÑÑ ÐºÐ°Ð»ÑкÑлÑÑоÑом."); Calculator calculator = new Calculator(persons); while (true) { System.out.println("ÐведиÑе название ÑоваÑа:"); String nameOfProduct = scanner.nextLine().trim(); if (nameOfProduct.isEmpty()) { System.out.println("ÐÑибка: некоÑÑекÑÐ½Ð°Ñ Ð´Ð»Ð¸Ð½Ð° Ð½Ð°Ð·Ð²Ð°Ð½Ð¸Ñ ÑоваÑа."); } else { double costOfProduct; while (true) { System.out.println("ÐведиÑе ÑÑоимоÑÑÑ ÑоваÑа (ФоÑмаÑ: ÑÑбли,копейки):"); try { costOfProduct = scanner.nextDouble(); scanner.nextLine(); if (costOfProduct <= 0.00) { System.out.println("ÐÑибка: некоÑÑекÑÐ½Ð°Ñ Ñена, введиÑе положиÑелÑное ÑиÑло."); } else break; } catch (InputMismatchException e) { System.out.println("ÐÑибка: недопÑÑÑимÑй Ñип ввода."); scanner.nextLine(); } } // Ðожно ÑоздаваÑÑ Ð¸ добавлÑÑÑ Ð² ÑпиÑок новÑй пÑодÑÐºÑ Product product = new Product(nameOfProduct, costOfProduct); calculator.addProduct(product); System.out.println("ÐобавиÑÑ ÐµÑÑ ÑоваÑ?"); String usersAnswer = scanner.nextLine(); if (usersAnswer.equalsIgnoreCase("завеÑÑиÑÑ")) break; } } // ÐÑвод ÑезÑлÑÑаÑов полÑзоваÑÐµÐ»Ñ calculator.displayProducts(); double scoreForEachPerson = calculator.calculateScoreForEachPerson(); System.out.println("ÐÑÐ¾Ð³Ð¾Ð²Ð°Ñ ÑÑоимоÑÑÑ: " + formatter.roundingTheDouble(scoreForEachPerson) + formatter.displayCurrency(scoreForEachPerson)); break; } } catch (InputMismatchException e) { System.out.println("ÐÑибка: недопÑÑÑимÑй Ñип ввода. ТÑебÑеÑÑÑ Ð²Ð²ÐµÑÑи Ñелое ÑиÑло."); scanner.nextLine(); } } scanner.close(); } }