import java.util.Scanner; public class Goods { private double totalBill = 0; private String goods = ""; /** ÐеÑод ÑÐ¾Ð·Ð´Ð°ÐµÑ String Ñо ÑпиÑком ÑоваÑов и Ð¸Ñ Ñеной, а Ñакже ÑÑммиÑÑÐµÑ Ð²Ñе ÑоваÑÑ Ð² оÑделÑнÑÑ Ð¿ÐµÑеменнÑÑ totalBill */ public void createListOfGoods() { String tempGoods = ""; String userInputGoodName; double userInputGoodValue; Scanner scanner = new Scanner(System.in); while (true) { if (tempGoods.isEmpty()) { System.out.println("ÐведиÑе название ÑоваÑа (Ðли \"ÐавеÑÑиÑÑ\" Ð´Ð»Ñ Ð¾ÐºÐ¾Ð½ÑÐ°Ð½Ð¸Ñ ÑоÑмиÑÐ¾Ð²Ð°Ð½Ð¸Ñ ÑпиÑка):"); } else { System.out.println("ÐведиÑе название ÑледÑÑÑего ÑоваÑа (Ðли \"ÐавеÑÑиÑÑ\" Ð´Ð»Ñ Ð¾ÐºÐ¾Ð½ÑÐ°Ð½Ð¸Ñ ÑоÑмиÑÐ¾Ð²Ð°Ð½Ð¸Ñ ÑпиÑка):"); } userInputGoodName = scanner.nextLine(); if (userInputGoodName.equalsIgnoreCase("ÐавеÑÑиÑÑ")) { break; } if (tempGoods.isEmpty()) { tempGoods = tempGoods.concat(userInputGoodName); } else { tempGoods = tempGoods.concat("\n" + userInputGoodName); } System.out.println("ÐведиÑе ÑÑоимоÑÑÑ ÑоваÑа в ÑоÑмаÑе ÑÑбли.копейки (напÑÐ¸Ð¼ÐµÑ 10.22):"); while (true) { userInputGoodValue = checkUserInputAsDouble(); if (userInputGoodValue < 0) { System.out.println("СÑоимоÑÑÑ ÑоваÑа должна бÑÑÑ Ð½ÐµÐ¾ÑÑиÑаÑелÑной"); } else { break; } } totalBill += userInputGoodValue; tempGoods = tempGoods.concat(String.format(" - Цена: %.2f", userInputGoodValue)); } goods = tempGoods; } /** ÐеÑод пÑовеÑÑеÑ, ÑвлÑеÑÑÑ Ð»Ð¸ ввод полÑзоваÑÐµÐ»Ñ double */ private double checkUserInputAsDouble() { Scanner scanner = new Scanner(System.in); double correctDoubleInput; while (true) { try { correctDoubleInput = Double.parseDouble(scanner.next()); break; } catch (NumberFormatException e) { System.out.println("ÐведиÑе коÑÑекÑнÑÑ ÑÑоимоÑÑÑ Ð² ÑоÑмаÑе ÑÑбли.копейки (напÑÐ¸Ð¼ÐµÑ 10.22):"); } } return correctDoubleInput; } /** ÐеÑод вÑводиÑ, ÑколÑко каждÑй Ñеловек должен заплаÑиÑÑ Ð² завиÑимоÑÑи Ð¾Ñ Ð²Ð²ÐµÐ´ÐµÐ½Ð½Ð¾Ð³Ð¾ колиÑеÑÑва гоÑÑей */ public void calculateAndShowResultsPerGuest(int numberOfGuests) { if (goods.isEmpty()) { System.out.println("ÐÐ¸ÐºÐ°ÐºÐ¸Ñ ÑоваÑов не бÑло добавлено"); return; } System.out.println("ÐобавленнÑе ÑоваÑÑ: \n" + goods); double billPerPerson = totalBill / numberOfGuests; String roubles = RoubleFormatter.returnRoubleString(billPerPerson); System.out.println(String.format("ÐаждÑй Ñеловек должен заплаÑиÑÑ %.2f %s", billPerPerson, roubles)); } }