diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..61a9130
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
new file mode 100644
index 0000000..6cec569
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..a47d29e
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/Calculate.java b/src/main/java/Calculate.java
new file mode 100644
index 0000000..6244d66
--- /dev/null
+++ b/src/main/java/Calculate.java
@@ -0,0 +1,68 @@
+import java.util.Scanner;
+
+public class Calculate {
+
+ class Product {
+ String name;
+ float price;
+
+ void input() {
+ Scanner scanner = new Scanner(System.in);
+ System.out.println("Введите наименование товара");
+ name = scanner.next();
+
+ System.out.println("Введите стоимость товара в формате 'рубли.копейки'");
+ while (true) {
+ if (scanner.hasNextFloat()) {
+ price = scanner.nextFloat();
+ if (price < 0) {
+ System.out.println("Введено недопустимое значение. Введите целое число больше 0");
+ scanner.nextLine();
+ } else {
+ break;
+ }
+ } else {
+ System.out.println("Введено недопустимое значение. Введите целое число больше 0");
+ scanner.nextLine();
+ }
+ }
+ }
+ }
+
+ Product product = new Product(); // создали новый объект класса Product
+ float sum = 0.00f; // переменная для хранения суммы чека
+ String order = ""; // переменная для хранения перечня продуктов
+ Scanner scannerAdd = new Scanner(System.in);
+ int guests = CountOfGuests.countOfGuests(); // число гостей, на которых делим счет
+
+ public void bill() {
+ while (true) {
+ product.input();
+
+ order = order.concat(product.name).concat("\n");
+ sum = sum + product.price;
+
+ System.out.println("Товар успешно добавлен в калькулятор!");
+ System.out.println("Чтобы завершить добавление товаров введите команду Завершить.\n\nДля продолжения внесения товаров в калькулятор введите любое другое значение.");
+ String add = scannerAdd.next();
+ if (add.equalsIgnoreCase("Завершить")) {
+ System.out.println("Список товаров:\n" + order);
+ float guestDebt = sum / guests; // расчёт суммы для каждого гостя
+ if ((Math.floor(guestDebt) % 100 >= 11) && (Math.floor(guestDebt) % 100 <= 19)) {
+ String format = "Каждый гость должен: %.2f рублей";
+ System.out.println(String.format(format, guestDebt));
+ } else if (Math.floor(guestDebt) % 10 > 5) {
+ String format = "Каждый гость должен: %.2f рублей";
+ System.out.println(String.format(format, guestDebt));
+ } else if ((2 <= Math.floor(guestDebt) % 10) && (Math.floor(guestDebt) % 10 <= 4)) {
+ String format = "Каждый гость должен: %.2f рубля";
+ System.out.println(String.format(format, guestDebt));
+ } else {
+ String format = "Каждый гость должен: %.2f рубль";
+ System.out.println(String.format(format, guestDebt));
+ }
+ break;
+ }
+ }
+ }
+ }
diff --git a/src/main/java/CountOfGuests.java b/src/main/java/CountOfGuests.java
new file mode 100644
index 0000000..0ea3dff
--- /dev/null
+++ b/src/main/java/CountOfGuests.java
@@ -0,0 +1,28 @@
+import java.util.Scanner;
+
+public class CountOfGuests {
+
+ static int count; // число гостей
+ static Scanner scanner = new Scanner(System.in);
+
+ public static int countOfGuests() {
+ System.out.println("Здравствуйте! На сколько человек необходимо разделить счет?");
+ while (true) {
+ if (scanner.hasNextInt()) {
+ int i = scanner.nextInt();
+ if (i == 1) {
+ System.out.println("Для одного гостя разбивать счёт нет необходимости. Введите другое число гостей");
+ } else if (i < 1) {
+ System.out.println("Гости не пришли. Платить некому. Введите другое число гостей.");
+ } else {
+ count = i; // запомнили число гостей
+ break;
+ }
+ } else {
+ System.out.println("Введите целое число");
+ scanner.nextLine();
+ }
+ }
+ return count;
+ }
+}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index a9198c4..2b061b4 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,8 +1,8 @@
public class Main {
public static void main(String[] args) {
- // ваш код начнется здесь
- // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
- System.out.println("Привет Мир");
+
+ Calculate calculate = new Calculate();
+ calculate.bill();
}
-}
+}
\ No newline at end of file