import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Calculator calculator = new Calculator(); Formatter formatter = new Formatter(); int numbOfPersons = getNumbOfPersons(scanner); while (true) { System.out.println("ÐведиÑе название ÑоваÑа"); String nameProduct = scanner.next(); double price = getPrice(scanner); calculator.addProduct(nameProduct, price); System.out.println("Ð¢Ð¾Ð²Ð°Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½"); System.out.println("ХоÑиÑе добавиÑÑ ÐµÑе один ÑоваÑ? Ðа/ÐавеÑÑиÑÑ"); String answer = scanner.next().toLowerCase(); if (answer.equals("завеÑÑиÑÑ")) { break; } } System.out.println(calculator.products); double priceForPerson = calculator.priceForPerson(numbOfPersons); String result = formatter.formatRub(priceForPerson); System.out.println("ÐаждÑй должен заплаÑиÑÑ: " + result); } private static double getPrice(Scanner scanner) { double price = 0; while (price <= 0) { System.out.println("ÐведиÑе ÑÐµÐ½Ñ Ð² ÑоÑмаÑе \"ÑÑблей.копеек\" (напÑÐ¸Ð¼ÐµÑ 123.45)"); String input = scanner.next(); if (input.length() >= 4 && input.charAt(input.length() - 3) == '.') { try { price = Double.parseDouble(input); if (price <= 0) { System.out.println("Цена ÑоваÑа должна бÑÑÑ Ð±Ð¾Ð»ÑÑе нÑлÑ"); } } catch (NumberFormatException e) { System.out.println("ÐÑоизоÑла непÑÐµÐ´Ð²Ð¸Ð´ÐµÐ½Ð½Ð°Ñ Ð¾Ñибка пÑи пÑеобÑазовании ÑÑÑоки в ÑиÑло."); } } else { System.out.println("ÐепÑавилÑнÑй ÑоÑÐ¼Ð°Ñ Ð²Ð²Ð¾Ð´Ð°."); } } return price; } private static int getNumbOfPersons(Scanner scanner) { int numbOfPersons = 0; while (numbOfPersons <= 1) { System.out.println("Ðа ÑколÑко Ñеловек Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ð¾ ÑазделиÑÑ ÑÑеÑ?"); String input = scanner.next(); try { numbOfPersons = Integer.parseInt(input); if (numbOfPersons <= 1) { System.out.println("ÐÑибка. ЧиÑло должно бÑÑÑ Ð±Ð¾Ð»ÑÑе 1"); } } catch (NumberFormatException e) { System.out.println("ÐÑибка. ÐведиÑе Ñелое ÑиÑло"); } } return numbOfPersons; } }