import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Ðлок 1. ÐÑинимаем Ð¾Ñ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ ÐºÐ¾Ð»-во Ñеловек:
int numberPeople = getNumberPeople(scanner);
// Ðлок 2. ÐÑинимаем Ð¾Ñ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ ÐºÐ°Ð¶Ð´Ñй ÑÐ¾Ð²Ð°Ñ Ð¸ его ÑÑоимоÑÑÑ:
ArrayList allProducts = getArrayOfProducts(scanner);
// Ðлок 3. ÐÑвод:
System.out.println("ÐобавленнÑе ÑоваÑÑ:");
double sumCost = 0;
for (Product product : allProducts) {
System.out.printf("%s - %.2f %s.\n", product.name, product.cost, Formater.getWordRuble(product.cost));
sumCost += product.cost;
}
double payFromEveryPerson = sumCost / numberPeople;
String wordRuble = Formater.getWordRuble(payFromEveryPerson);
System.out.printf("ÐаждÑй Ñеловек должен заплаÑиÑÑ \"%.2f\" %s.", payFromEveryPerson, wordRuble);
}
public static int getNumberPeople(Scanner scanner) {
System.out.println("Ðа ÑколÑкиÑ
Ñеловек необÑ
одимо ÑазделиÑÑ ÑÑÑÑ:");
while (true) {
int numberPeople = Checker.checkInt(scanner);
if (numberPeople == 1) {
System.out.println("ÐолиÑеÑÑво Ñеловек, введÑннÑÑ
полÑзоваÑелем, Ñавно 1. ÐеÑего делиÑÑ. ÐопÑобÑйÑе Ñнова:");
} else if (numberPeople < 1) {
System.out.println("ÐекоÑÑекÑное знаÑение Ð´Ð»Ñ Ð¿Ð¾Ð´ÑÑÑÑа. ÐопÑобÑйÑе еÑÑ Ñаз:");
} else
return numberPeople;
}
}
public static ArrayList getArrayOfProducts(Scanner scanner) {
scanner.nextLine();
ArrayList allProducts = new ArrayList<>();
while (true) {
System.out.println("ÐведиÑе название ÑоваÑа:");
String goodName = scanner.nextLine();
if (goodName.trim().isEmpty()) {
System.out.println("Ðазвание ÑоваÑа не должно бÑÑÑ Ð¿ÑÑÑÑм или ÑодеÑжаÑÑ ÑолÑко пÑобелÑ.");
} else {
System.out.println("ÐведиÑе ÑÑоимоÑÑÑ ÑоваÑа:");
double goodCost = Checker.checkCost(scanner);
Product product = new Product(goodName.trim(), goodCost);
allProducts.add(product);
System.out.println("Ð¢Ð¾Ð²Ð°Ñ ÑÑпеÑно добавлен.");
System.out.println("ХоÑиÑе добавиÑÑ ÐµÑÑ Ð¾Ð´Ð¸Ð½ ÑоваÑ?");
scanner.nextLine();
String isItEnd = scanner.nextLine();
if (isItEnd.equalsIgnoreCase("завеÑÑиÑÑ"))
break;
}
}
return allProducts;
}
}