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);
People people = new People();
int numberPeople = people.reqCountOfPeople(scanner);
if (numberPeople < 1){
System.out.println("Ðидимо никÑо не пÑиÑел, ÑÑÐµÑ Ð½Ðµ на кого не поделиÑÑ");
}
AddTovarAndSave addTovarAndSave = new AddTovarAndSave();
addTovarAndSave.addBludo(scanner);
List addedTovars = addTovarAndSave.getAddedTovars();
System.out.println("ÐобавленнÑе ÑоваÑÑ:");
for (TovarAndPrice tovar : addedTovars) {
System.out.println(tovar.getTovarName() + ": " + formatCurrency(tovar.getTovarPrice()));
}
double allSumma = addTovarAndSave.getAllSumma();
double onePersonSumma = allSumma / numberPeople;
System.out.println("ÐбÑий ÑÑеÑ: " + formatCurrency (allSumma));
System.out.println("СÑмма на каждого: " + formatCurrency (onePersonSumma));
}
private static String formatCurrency(double amount) {
String formattedAmount = String.format("%.2f", amount);
formattedAmount = formattedAmount.replace(',', '.'); // ÐамениÑÑ Ð·Ð°Ð¿ÑÑÑÑ Ð½Ð° ÑоÑкÑ
String[] parts = formattedAmount.split("\\.");
int integerPart = (int) Double.parseDouble(parts[0]);
if (integerPart % 10 == 1 && integerPart % 100 != 11) {
return formattedAmount + " ÑÑблÑ";
} else if ((integerPart % 10 >= 2 && integerPart % 10 <= 4) && (integerPart % 100 < 12 || integerPart % 100 > 14)) {
return formattedAmount + " ÑÑблÑ";
} else {
return formattedAmount + " ÑÑблей";
}
}
}