import java.util.ArrayList;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
AccountCalculator Ñalculator = new AccountCalculator();
Ñalculator.start();
}
}
class AccountCalculator {
ArrayList ÑalculatorList = new ArrayList<>();
ArrayList ÑalculatorDouble = new ArrayList<>();
int userInput;
String productName;
Double productPrice;
String productPriceString;
String finish;
Double totalСost = 00.00;
private void Ñalculator() {
Scanner scanner = new Scanner(System.in);
System.out.println("ÐведиÑе название ÑоваÑа:");
productName = scanner.next();
ÑalculatorList.add(productName);
System.out.println("ÐведиÑе ÑÑоимоÑÑÑ Ð² ÑоÑмаÑе 00,00 ÑÑб.коп.:");
productPriceString = scanner.next();
productPriceString = productPriceString.replaceAll(",", ".");
while (!isNumeric(productPriceString)) {
System.out.print("ÐÑ Ð²Ð²ÐµÐ»Ð¸ некоÑÑекÑное знаÑение\n");
productPriceString = scanner.next();
}
productPrice = Double.parseDouble(productPriceString);
ÑalculatorDouble.add(productPrice);
totalСost = totalСost + productPrice;
String result = String.format("%.2f", totalСost);
System.out.print("\nСпиÑок добавленного ÑоваÑа:\n");
for (int i = 0; i < ÑalculatorList.size(); i++) {
String name = ÑalculatorList.get(i);
double price = ÑalculatorDouble.get(i);
String rubName = " ÑÑблÑ";
int rub1 = (int) price;
switch (rub1 % 10){ case 1:
rubName = " ÑÑблÑ"; break;
case 2: case 3: case 4:
rubName = " ÑÑблÑ"; break;
case 5: case 6: case 7: case 8: case 9: case 0:
rubName = " ÑÑблей";
}
System.out.print(i+1 + " " + name + " " + price + " " + rubName + "\n");
}
System.out.print("ÐбÑÐ°Ñ ÑÑоимоÑÑÑ: " + result + "\n \n");
System.out.print("Ð¢Ð¾Ð²Ð°Ñ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½ ÑÑпеÑно! \nЧÑÐ¾Ð±Ñ Ð¿ÑодолжиÑÑ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ðµ ÑоваÑа введиÑе лÑбой Ñимвол \nЧÑÐ¾Ð±Ñ Ð·Ð°Ð²ÐµÑÑиÑÑ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½Ð¸Ñ ÑоваÑа введиÑе ÐºÐ¾Ð¼Ð°Ð½Ð´Ñ 'ÐавеÑÑиÑÑ'\n");
finish = scanner.next();
finish (finish, userInput, totalСost);
}
private void finish (String finish, int userInput, double totalСost) {
String fin = "ÐавеÑÑиÑÑ";
String finСost = String.format("%.2f", (totalСost/userInput));
System.out.print("\nСпиÑок добавленного ÑоваÑа:\n");
for (int i = 0; i < ÑalculatorList.size(); i++) {
String name = ÑalculatorList.get(i);
double price = ÑalculatorDouble.get(i);
int namb = i;
String rubName = " ÑÑблÑ";
int rub1 = (int) price;
switch (rub1 % 10){ case 1:
rubName = " ÑÑблÑ"; break;
case 2: case 3: case 4:
rubName = " ÑÑблÑ"; break;
case 5: case 6: case 7: case 8: case 9: case 0:
rubName = " ÑÑблей";
}
System.out.print(++namb + " " + name + " " + price + " " + rubName + "\n");
}
if (finish.equalsIgnoreCase(fin)) {
System.out.print("Ðелим ÑÑеÑ\n");
System.out.print("ÐаждÑй должен заплаÑиÑÑ " + finСost);
int rub = (int) totalСost/userInput;
switch (rub % 10){ case 1:
System.out.println(" ÑÑблÑ"); break;
case 2: case 3: case 4:
System.out.println(" ÑÑблÑ"); break;
case 5: case 6: case 7: case 8: case 9: case 0:
System.out.println(" ÑÑблей"); break;
}
} else {
Ñalculator();
}
}
public static boolean isNumeric(String productPriceString) {
try {
Double.parseDouble(productPriceString);
return true;
} catch (NumberFormatException e) {
return false;
}
}
public void start() {
Scanner scanner = new Scanner(System.in);
do {
System.out.println("Ðа ÑколÑкиÑ
Ñеловек необÑ
одимо ÑазделиÑÑ ÑÑÑÑ \n(ÐведиÑе колиÑеÑÑво Ñеловек более 1):");
while (!scanner.hasNextInt()) {
System.out.println("ÐÑо некоÑÑекÑное знаÑение Ð´Ð»Ñ Ð¿Ð¾Ð´ÑÑÑÑа \n\n Ðа ÑколÑкиÑ
Ñеловек необÑ
одимо ÑазделиÑÑ ÑÑÑÑ \n(ÐведиÑе колиÑеÑÑво Ñеловек более 1):");
scanner.next();
}
userInput = scanner.nextInt();
if (userInput <=1) {
System.out.println("ÐÑибка");
start();
}
} while (userInput <= 1);
System.out.println("ÐÑдем делиÑÑ ÑÑÑÑ Ð½Ð° " + userInput + " Ñел.");
Ñalculator();
}
}