import java.util.ArrayList;
import java.util.Iterator;
import java.util.Scanner;
class RubFormat{
int rub;
String formatter(int rub){
this.rub = rub;
String ruble = "";
if (rub >= 10){
ruble = "Ð Ñблей";
} else {
switch (rub){
case 1:
ruble = "Ð ÑблÑ";
break;
case 2:
case 3:
case 4:
ruble = "Ð ÑблÑ";
break;
case 0:
case 5:
case 6:
case 7:
case 8:
case 9:
ruble = "Ð Ñблей";
break;
}
}
return ruble;
}
}
class Product{
String name;
float price;
Product(String name,float price){
this.name = name;
this.price = price;
}
}
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList products = new ArrayList<>();
System.out.println("ÐведиÑе колиÑеÑÑво гоÑÑей ÑÑеди коÑоÑÑÑ
нÑжно ÑазделиÑÑ ÑÑÑÑ");
int peoples = 0;
float sum = 0;
while (true){
if (sc.hasNextInt()) {
peoples = sc.nextInt();
if (peoples < 1) {
System.out.println("ÐведиÑе пÑавилÑное колиÑеÑÑво гоÑÑей");
continue;
} else if (peoples == 1){
System.out.println("ÐелиÑÑ Ð½Ðµ нÑжно, ÐºÐ¾Ð½ÐµÑ Ð¿ÑогÑаммÑ");
return;
} else {
System.out.println("ÐолиÑеÑÑво гоÑÑей: " + peoples);
break;
}
} else {
System.out.println("ÐведиÑе Ñелое ÑиÑло гоÑÑей");
//sc.next();
continue;
}
}
sc.nextLine();
while(true){
System.out.println("ÐведиÑе название ÑоваÑа или 'ÐавеÑÑиÑÑ' Ð´Ð»Ñ Ð¾ÑменÑ");
String name = sc.nextLine();
if (name.isEmpty()){
System.out.println("Ðазвание ÑоваÑа не Ð¼Ð¾Ð¶ÐµÑ Ð±ÑÑÑ Ð¿ÑÑÑÑм");
continue;
} else if (name.matches("\\d+")){
System.out.println("Ðазвание ÑоваÑа не Ð¼Ð¾Ð¶ÐµÑ ÑоÑÑоÑÑÑ ÑолÑко из ÑиÑÑ");
continue;
} else if (name.equalsIgnoreCase("ÐавеÑÑиÑÑ")) {
break;
}
System.out.println("ÐведиÑе ÑÐµÐ½Ñ ÑоваÑа");
while(true){
if(sc.hasNextFloat()){
float price = sc.nextFloat();
sc.nextLine();
if (price > 0){
products.add(new Product(name,price));
sum += price;
System.out.println("Ð¢Ð¾Ð²Ð°Ñ " + name + " добавлен Ñо ÑÑоимоÑÑÑÑ " + price);
break;
} else System.out.println("ÐведиÑе коÑÑекÑнÑÑ ÑÐµÐ½Ñ ÑоваÑа");
} else {
System.out.println("ÐведиÑе ÑиÑло");
sc.next();
}
}
}
if (products.isEmpty()) {
System.out.println("ÐÑ Ð½Ðµ добавили ни одного ÑоваÑа");
} else System.out.println("ÐобавленнÑе ÑоваÑÑ: ");
;
for (int i = 0; i < products.size(); i++){
System.out.println("ТоваÑ: " + products.get(i).name + " ÑÑоимоÑÑÑÑ: " + products.get(i).price);
}
RubFormat rubFormat = new RubFormat();
float totalSum = sum/(float)peoples;
int rub = (int) totalSum;
if ((int)totalSum > 10 && (int)totalSum <= 20) {
rub = (int) totalSum;
} else {
rub = (int) totalSum % 10;
}
String ruble = rubFormat.formatter(rub);
System.out.print(String.format("ÐаждÑй гоÑÑÑ Ð´Ð¾Ð»Ð¶ÐµÐ½ заплаÑиÑÑ: %.2f %s",totalSum, ruble ));
}
}