import java.util.Scanner; public class Main { // private static final Scanner scanner = new Scanner(System.in); public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numberOfPeople; double costOfGoods; // 1. Ðводим колиÑеÑÑво поÑеÑиÑелей. System.out.println("Ðа ÑколÑÐºÐ¸Ñ Ñеловек ÑазделиÑÑ ÑÑеÑ?"); while (true) { while (!sc.hasNextInt()) { System.out.println("ÐекоÑÑекÑнÑй ввод, введиÑе Ñелое ÑиÑло."); sc.next(); } numberOfPeople = sc.nextInt(); if (numberOfPeople <=1) { System.out.println("ÐолиÑеÑÑво поÑеÑиÑелей должно бÑÑÑ Ð±Ð¾Ð»ÑÑе 1."); } else { System.out.println("ÐолиÑеÑÑво поÑеÑиÑелей - " + numberOfPeople); break; } } Calculator calc = new Calculator(); // 2.1 Ðводим название ÑоваÑа while (true) { System.out.println("ÐведиÑе название ÑоваÑа"); String productName = sc.next(); if (productName.equalsIgnoreCase("ÐÐÐÐРШÐТЬ")){ // 3.1 ÐÑводим ÑпиÑок ÑоваÑов System.out.println(calc.listOfProducts); // 3.2 ÐÑводим ÑÐµÐ½Ñ Ð´Ð»Ñ Ð¾Ð´Ð½Ð¾Ð³Ð¾ Ñеловека double costPerPerson = calc.totalAmount / (double) numberOfPeople; System.out.println(String.format("%.2f",costPerPerson) + " " + GetCurrency(costPerPerson)); break; } else { while (true) { // 2.2 Ðводим ÑÑоимоÑÑÑ ÑоваÑа System.out.println("ÐведиÑе ÑÑоимоÑÑÑ ÑоваÑа"); while (!sc.hasNextDouble()) { System.out.println("ÐекоÑÑекÑнÑй ввод, введиÑе ÑиÑло."); sc.next(); } costOfGoods = sc.nextDouble(); if (costOfGoods > 0) { calc.AddProductToCalculator(productName,costOfGoods); break; } else { System.out.println("ÐведиÑе не нÑлевÑÑ ÑÑоимоÑÑÑ ÑоваÑа." + numberOfPeople); } } } } //while (true) } public static String GetCurrency(double costPerPerson){ String currency = "ÑÑблей"; int integerPartOfNumber = (int)costPerPerson; String strIntegerPartOfNumber = Integer.toString(integerPartOfNumber); String theLastDigit = strIntegerPartOfNumber.substring(strIntegerPartOfNumber.length() - 1); if (theLastDigit.equals("1")){ currency = "ÑÑблÑ"; } else if (theLastDigit.equals("2") || theLastDigit.equals("3") || theLastDigit.equals("4")) { currency = "ÑÑблÑ"; } return currency; } }