import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Scanner;
public class Main {
static ArrayList products = new ArrayList<>();
public static void main(String[] args) {
boolean correctCustomersNumberEntered = false;
int customers = 0;
Scanner s = new Scanner(System.in);
System.out.println("Ðа ÑколÑкиÑ
Ñеловек необÑ
одимо ÑазделиÑÑ ÑÑÑÑ?");
do {
try {
customers = s.nextInt();
correctCustomersNumberEntered = true;
} catch (InputMismatchException e) {
System.out.println ("ÐÑо некоÑÑекÑное знаÑение гоÑÑей. ÐведиÑе коÑÑекÑное колиÑеÑÑво гоÑÑей.");
s.nextLine();
}
} while (!correctCustomersNumberEntered);
while (customers <= 1) {
System.out.println("ÐÑо некоÑÑекÑное знаÑение Ð´Ð»Ñ Ð¿Ð¾Ð´ÑÑÑÑа.\nÐведиÑе коÑÑекÑное колиÑеÑÑво гоÑÑей. ÐÑли гоÑÑей менÑÑе двÑÑ
, Ñо ÑаÑÑÐµÑ Ð½Ðµ ÑÑебÑеÑÑÑ");
customers = s.nextInt();
}
outer:
while (true) {
System.out.println("УкажиÑе наименование ÑоваÑа:");
String product = s.next();
System.out.println("УкажиÑе ÑÑоимоÑÑÑ ÑоваÑа в ÑоÑмаÑе 'ÑÑбли.копейки' [10.45, 11.40]:");
double price = 0;
boolean correctPriceEntered = false;
do {
try {
price = s.nextDouble();
if (price <= 0) {
System.out.println("ÐекоÑÑекÑнÑй ввод.Ð¢Ð¾Ð²Ð°Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ бÑÑÑ Ñказан в коÑÑекÑном ÑоÑмаÑе 'ÑÑбли.копейки' [10.45, 11.40]");
s.nextLine();
} else {
correctPriceEntered = true;
}
} catch (InputMismatchException e) {
System.out.println("Ð¢Ð¾Ð²Ð°Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ бÑÑÑ Ñказан в коÑÑекÑном ÑоÑмаÑе 'ÑÑбли.копейки' [10.45, 11.40]");
s.nextLine();
}
} while (!correctPriceEntered);
Product p = new Product(product, price);
Calculator.addProduct(p);
products.add(p);
String enough;
do {
System.out.println("ÐобавиÑÑ ÐµÑе ÑоваÑов в заказ (Ðа/ÐеÑ)?");
enough = s.next();
if (enough.equalsIgnoreCase("неÑ")) {
System.out.println("ÐобавленнÑе ÑоваÑÑ:");
for (int i = 0; i < products.size(); i++) {
System.out.println(products.get(i).getLabel());
}
System.out.println("ÐаждÑй поÑиÑеÑÐ»Ñ Ð´Ð¾Ð»Ð¶ÐµÐ½ заплаÑиÑÑ" + " " + Calculator.calculateBill(customers));
break outer;
} else if (enough.equalsIgnoreCase("да")) {
break;
} else {
System.out.println("ÐекоÑÑекÑнÑй ввод");
}
} while (true);
}
}
}