import java.util.InputMismatchException; import java.util.Scanner; public class Main { public static void main(String[] args) { int numberOfUsers = -1; Scanner scanner = new Scanner(System.in); // Создаем ÑкземплÑÑ ÐºÐ»Ð°ÑÑа Scanner. Calculator calculator = new Calculator(); numberOfUsers = getNumberOfPeople(scanner); getProductsInfo(scanner, calculator); calculator.showCheck(numberOfUsers); scanner.close(); // ÐакÑÑваем Scanner по завеÑÑении ÑабоÑÑ. } public static int getNumberOfPeople(Scanner scan) { int numb = -1; while (true) { System.out.println("ÐведиÑе, на ÑколÑÐºÐ¸Ñ Ñеловек Ð½ÐµÐ¾Ð±Ñ Ð¾Ð´Ð¸Ð¼Ð¾ ÑазделиÑÑ ÑÑÑÑ"); numb = getInt(scan); if (numb > 1) { break; } else { System.err.println("ÐекоÑÑекÑное ÑиÑло"); } } return numb; } public static void getProductsInfo(Scanner scan, Calculator calculator) { while (true) { String nameOfProduct = ""; float priceOfProduct = 0; System.out.println("ÐведиÑе название ÑоваÑа"); nameOfProduct = scan.next(); while (priceOfProduct <= 0) { System.out.println("ÐведиÑе ÑÐµÐ½Ñ ÑоваÑа"); priceOfProduct = getFloat(scan); if (priceOfProduct > 0) { calculator.add(priceOfProduct); calculator.writeToTheList(nameOfProduct, priceOfProduct); System.out.println("Ð¢Ð¾Ð²Ð°Ñ ÑÑпеÑно добавлен"); } else { System.err.println("ÐекоÑÑекÑÐ½Ð°Ñ Ñена!"); } } System.out.println("ÐÑодолжиÑÑ Ð²Ð²Ð¾Ð´ ÑоваÑов? ÐведиÑе \"ÐавеÑÑиÑÑ\"," + " еÑли Ñ Ð¾ÑиÑе оконÑиÑÑ Ð²Ð²Ð¾Ð´ ÑоваÑов, или лÑбой Ñимвол, еÑли Ñ Ð¾ÑиÑе пÑодолжиÑÑ Ð²Ð²Ð¾Ð´"); String command = scan.next(); if (command.equalsIgnoreCase("ÐавеÑÑиÑÑ")) { break; } } } public static float getFloat(Scanner scan) { try { float number = scan.nextFloat(); return number; } catch (InputMismatchException e) { scan.nextLine(); return 0; } } public static int getInt(Scanner scan) { try { int number = scan.nextInt(); return number; } catch (InputMismatchException e) { scan.nextLine(); return 0; } } }