import java.util.ArrayList;
import java.util.Scanner;
public class Calculator {
public Calculator(int totalPersons) {
this.totalPersons = totalPersons;
}
static ArrayList products = new ArrayList<>();
static int totalPersons;
static double calculate(){
double sum = 0;
for (Product product:products) {sum += product.price;}
return sum;
}
static void addProducts(){
Scanner scanner = new Scanner(System.in);
System.out.println("ÐдÑавÑÑвÑйÑе!");
System.out.println("СделайÑе заказ (Ð´Ð»Ñ Ð·Ð°Ð²ÐµÑÑÐµÐ½Ð¸Ñ Ð²Ð²ÐµÐ´Ð¸Ñе 'завеÑÑиÑÑ'): ");
String productName;
double productPrice;
double totalPrice = 0;
Declension roubles;
do {
System.out.print("Ðаименование ÑоваÑа: ");
productName = scanner.nextLine();
if (!productName.equalsIgnoreCase("завеÑÑиÑÑ")) {
System.out.print("Цена ÑоваÑа: ");
while (!scanner.hasNextDouble()) {
System.out.println("ÐекоÑÑекÑное знаÑение. ÐовÑоÑиÑе ввод");
scanner.next();
}
productPrice = scanner.nextDouble();
scanner.nextLine();
if (productPrice > 0) {
Product product = new Product(productName, productPrice);
roubles = new Declension(product.price);
System.out.println("Ð¢Ð¾Ð²Ð°Ñ '" + product.name + "' добавлен в ÑÑеÑ, ÑÑоимоÑÑÑ: " + String.format("%.2f", product.price)+roubles.getDeclension());
products.add(product);
totalPrice = calculate();
roubles = new Declension(totalPrice);
System.out.println("Ðобавлено ÑоваÑов на ÑÑÐ¼Ð¼Ñ "+String.format("%.2f", totalPrice) + roubles.getDeclension());
} else {
System.out.println("ÐведиÑе ÑÐµÐ½Ñ ÑоваÑа болÑÑе нÑлÑ");
}
}
} while (!productName.equalsIgnoreCase("завеÑÑиÑÑ"));
double result = totalPrice/totalPersons;
roubles = new Declension(result);
System.out.println("ÐаждÑй из Ð²Ð°Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ заплаÑиÑÑ Ð¿Ð¾ "+String.format("%.2f", result) +roubles.getDeclension());
}
}