import java.util.Scanner; public class Calculator { // ÐеÑод Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÐºÐ¾Ð»Ð¸ÑеÑÑва пеÑÑон public int addPerson(){ int person = -1; Scanner input = new Scanner(System.in); while (person <= 0) { System.out.println("ÐведиÑе колиÑеÑÑво пеÑÑон"); if (input.hasNextInt()) { person = input.nextInt(); if (person <= 0) { System.out.println("ÐÑ Ð²Ð²ÐµÐ»Ð¸ не веÑное колиÑеÑво пеÑÑон"); } } else { System.out.println("ÐÑ Ð²Ð²ÐµÐ»Ð¸ оÑибоÑное знаÑение"); input.next(); // Сдвиг ÑканеÑа, инаÑе беÑконеÑнÑй Ñикл } } return person; } private Product addProduct(){ String name = null; double cost = -1; Product product; Scanner input = new Scanner(System.in); System.out.println("ÐведиÑе название пÑодÑкÑа"); // Рназвание пÑинимаеÑÑÑ Ð»Ñбое знаÑение if(input.hasNext()) { name = input.next(); } System.out.println("ÐведиÑе ÑÑоимоÑÑÑ Ð¿ÑодÑкÑа в ÑоÑмаÑе \"ÑÑбли,копейки [10,45]\""); while (cost <= 0) { if (input.hasNextDouble()) { cost = input.nextDouble(); } else { System.out.println("ÐÑ Ð²Ð²ÐµÐ»Ð¸ не коÑÑекÑнÑÑ ÑÑоимоÑÑÑ"); input.next(); // Сдвиг } } System.out.println("ÐÑ Ð´Ð¾Ð±Ð°Ð²Ð¸Ð»Ð¸ ÑоваÑ: \"" + name + "\" ÑÑоимоÑÑÑÑ: " + cost); product = new Product(name,cost); return product; } //ÐолÑÑиÑÑ ÑпиÑок вÑÐµÑ Ð¿ÑодÑкÑов и ÑиналÑнÑÑ ÑÑоимоÑÑÑ public double summProducts() { String productsAllPerson = ""; double costAllPerson = 0; Scanner input = new Scanner(System.in); String answer; Product product; String strDialog; while(true) { System.out.println("ХоÑиÑе ли ÐÑ Ð´Ð¾Ð±Ð°Ð²Ð¸ÑÑ Ð½Ð¾Ð²Ñй пÑодÑкÑ? (Ðа/ÐеÑ/ÐавеÑÑиÑÑ)"); if (input.hasNext()) { answer = input.next(); if (answer.equalsIgnoreCase("да")) { product = addProduct(); productsAllPerson = productsAllPerson + product.productName + "\n"; costAllPerson = costAllPerson + product.cost; } if (answer.equalsIgnoreCase("неÑ") || answer.equalsIgnoreCase("завеÑÑиÑÑ")) { break; } } } strDialog = "ÐобавленнÑе ÑоваÑÑ:\n%s\nÐбÑей ÑÑоимоÑÑÑÑ: %.2f %s"; strDialog = String.format(strDialog, productsAllPerson, costAllPerson, getEnding(costAllPerson)); System.out.println(strDialog); return costAllPerson; } // Склонение ÑÑÐ±Ð»Ñ public String getEnding(double cost){ int preLast = (int)Math.floor(cost) % 100 / 10; if (preLast == 1){ return "ÑÑблей"; } switch ((int)Math.floor(cost) % 10){ case 1: return "ÑÑблÑ"; case 2: case 3: case 4: return "ÑÑблÑ"; default: return "ÑÑблей"; } } }