import java.util.Scanner; public class Calculator { Scanner scanner = new Scanner(System.in); double sum; String goods = ""; String currency; void addGoods() { while (true) { System.out.println("ÐведиÑе название ÑоваÑа: "); String addProduct = scanner.next(); goods = goods + addProduct + "\n" ; getPrice(); System.out.println("ХоÑиÑе добавиÑÑ ÐµÑе один ÑоваÑ? ÐÑли неÑ, введиÑе \"ÐавеÑÑиÑÑ\""); String answer = scanner.next(); if (answer.equalsIgnoreCase("ÐавеÑÑиÑÑ")) { break; } } } void getPrice() { while (true) { System.out.println("ÐведиÑе ÑÐµÐ½Ñ ÑоваÑа:"); if (scanner.hasNextDouble()) { double productPrice = scanner.nextDouble(); if (productPrice > 0) { sum += productPrice; System.out.println("Ð¢Ð¾Ð²Ð°Ñ ÑÑпеÑно добавлен!"); break; } else { System.out.println("ÐÑибка! Цена ÑоваÑа Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ ÑолÑко положиÑелÑной!"); } } else { System.out.println("ÐÑибка! ÐведиÑе коÑÑекÑнÑÑ ÑÐµÐ½Ñ ÑоваÑа!"); scanner.next(); } } } void calculatePayment(int numberOfPersons) { System.out.println("ÐобавленнÑе ÑоваÑÑ:\n" + goods); double sumPerPerson = sum / numberOfPersons; String sumToPay = String.format("СÑмма к оплаÑе на Ñеловека: %.2f", sumPerPerson); int sumToInt = (int)Math.floor(sumPerPerson); int secondLastDigit = (sumToInt % 100) / 10; int lastDigit = sumToInt % 10; if (lastDigit == 1 && secondLastDigit != 1) { currency = " ÑÑблÑ."; } else if (lastDigit <= 4 && lastDigit > 1 && secondLastDigit != 1) { currency = " ÑÑблÑ."; }else { currency = " ÑÑблей."; } System.out.println(sumToPay + currency); } }