public class Calculator { private int peopleCounter; private String addedProducts = "ÐобавленнÑе ÑоваÑÑ:\n"; private double totalPrice; public Calculator(int peopleCounter){ this.peopleCounter = peopleCounter; } public void addProduct(Product product){ addedProducts = addedProducts + product.getName() + "\n"; totalPrice += product.getPrice(); System.out.println("Ð¢Ð¾Ð²Ð°Ñ ÑÑпеÑно добавлен."); } public void showAddedProducts(){ System.out.println("\n" + addedProducts); } public void divide(){ double dividedPrice = totalPrice / (double) peopleCounter; String formattedPrice = formatPrice(dividedPrice); String currency = getCurrencyWriting(dividedPrice); System.out.println("ÐаждÑй Ñеловек должен заплаÑиÑÑ " + formattedPrice + " " + currency + "."); } private String formatPrice(double price){ return String.format("%,.2f", price); } private String getCurrencyWriting(double price){ double roundedPrice = Math.floor(price); double remainder = roundedPrice % 100.00; if (remainder >= 11 && remainder <= 14){ return "ÑÑблей"; } else { remainder = remainder % 10.00; if (remainder >= 1 && remainder < 2) { return "ÑÑблÑ"; } else if (remainder >= 2 && remainder <= 4) { return "ÑÑблÑ"; } else { return "ÑÑблей"; } } } }