import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
BillCalculator calculator = new BillCalculator();
System.out.println("Ðа ÑколÑкиÑ
Ñеловек необÑ
одимо ÑазделиÑÑ ÑÑÑÑ?");
int peopleCount;
while (true) {
try {
peopleCount = Integer.parseInt(scanner.nextLine());
if (peopleCount > 1) {
calculator.setNumberOfPeople(peopleCount);
break;
} else {
System.out.println("ÐведиÑе коÑÑекÑное колиÑеÑÑво лÑдей (болÑÑе 1):");
}
} catch (NumberFormatException e) {
System.out.println("ÐожалÑйÑÑа, введиÑе ÑиÑло.");
}
}
while (true) {
System.out.println("ÐведиÑе название ÑоваÑа и его ÑÑоимоÑÑÑ (или 'ÐавеÑÑиÑÑ' Ð´Ð»Ñ Ð·Ð°Ð²ÐµÑÑениÑ):");
String input = scanner.nextLine();
if ("ÐавеÑÑиÑÑ".equalsIgnoreCase(input)) {
break;
} else {
try {
String[] parts = input.split(" ");
String name = parts[0];
double price = Double.parseDouble(parts[1]);
calculator.addProduct(new Product(name, price));
System.out.println("Ð¢Ð¾Ð²Ð°Ñ '" + name + "' по Ñене " + price + " добавлен.");
} catch (Exception e) {
System.out.println("ÐекоÑÑекÑнÑй ввод, попÑобÑйÑе еÑе Ñаз.");
}
}
}
System.out.println("ÐобавленнÑе ÑоваÑÑ:");
calculator.getProducts().forEach(product -> System.out.println(product.getName() + " по Ñене " + product.getPrice()));
double amountPerPerson = calculator.getAmountPerPerson();
System.out.println("ÐаждÑй должен заплаÑиÑÑ: " + Formatter.formatAmount(amountPerPerson) + " " + Formatter.getRublesWord(amountPerPerson));
}
}
class Product {
private final String name;
private final double price;
public Product(String name, double price) {
this.name = name;
this.price = price;
}
public String getName() {
return name;
}
public double getPrice() {
return price;
}
}
class BillCalculator {
private final List