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/.name b/.idea/.name
new file mode 100644
index 0000000..962e712
--- /dev/null
+++ b/.idea/.name
@@ -0,0 +1 @@
+Java-Module-Project
\ No newline at end of file
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/Main.java b/src/main/java/Main.java
index a9198c4..fdbdb84 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,8 +1,121 @@
+import java.util.Scanner; // импорт сканера
+
public class Main {
public static void main(String[] args) {
- // ваш код начнется здесь
- // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
- System.out.println("Привет Мир");
+
+ Scanner scanner = new Scanner(System.in);
+ Calculator calc = new Calculator();
+ Product product = new Product();
+
+ System.out.println("На сколько человек нужно разделить счет?");
+ int payingGuests = 0;// создаем переменную - число гостей
+ boolean isGuestsNumberCorrect = false;
+ while(!isGuestsNumberCorrect) {
+ if(scanner.hasNextInt()) {
+ payingGuests = scanner.nextInt();
+ if(payingGuests> 1) {
+ isGuestsNumberCorrect = true;
+ scanner.nextLine();
+ } else {
+ System.out.println("Я не могу разделить на такое число гостей. Введите значение больше 1");
+ scanner.nextLine();
+ }
+ } else {
+ System.out.println("Вы ввели некорректное значение. Введите числовое значение больше 1");
+ scanner.nextLine();
+ }
+ }
+ System.out.println("Ввод корректен. Число гостей установлено: их ровно " + payingGuests); // тут мы разобрались с гостями, обработав некорректный ввод
+
+ while(true) {
+ System.out.println("Введите название товара:");
+ product.productName = scanner.nextLine();
+ System.out.println("Введите стоимость товара в формате \"рубли,копейки\"");
+
+ while(true) {
+ if (scanner.hasNextDouble()) {
+ product.productPrice = scanner.nextDouble();
+ if(product.productPrice> 0) {
+ scanner.nextLine();
+ break;
+ }
+ System.out.println("Стоимость товара должна быть больше 0. Введите корректное значение");
+ scanner.nextLine();
+ } else {
+ System.out.println("Вы ввели некорректное значение. Введите числовое значение больше нуля");
+ scanner.nextLine();
+ }
+ }
+ calc.add(product);
+ System.out.println("Добавить еще один товар? Введите \"Завершить\" чтобы узнать итоговую стоимость,\nили любой другой символ, чтобы добавить еще товары");
+ String userChoice = scanner.nextLine();
+ String enough = "Завершить";
+
+ if(userChoice.equalsIgnoreCase(enough)) {
+ break;
+ }
+ }
+
+ double guestTotal = calc.total/payingGuests;
+ String rubleTemplate ="%.2f";
+
+ System.out.println("Ваш список покупок:\n" + calc.shoppingList);
+ calc.findEnding(calc.total);
+ System.out.println("Итоговая стоимость покупок составила: " + String.format(rubleTemplate, calc.total) + " " + calc.ending);
+ calc.findEnding(guestTotal);
+ System.out.println("Каждый гость должен заплатить " + String.format(rubleTemplate, guestTotal) + " " + calc.ending);
+ }
+}
+
+class Calculator {
+ double total = 0;
+ String shoppingList = new String();
+ String ending = new String();
+
+ public void add(Product product) {
+ total += product.productPrice;
+ shoppingList += product.productName + " " + product.productPrice + "\n";
+
+ }
+
+ public void findEnding(double endingPrice) {
+
+ int intPrice = (int) Math.floor(endingPrice);
+
+ if(10 < intPrice % 100 && intPrice % 100 <= 19) {
+ ending = "рублей";
+ } else {
+ switch(intPrice % 10) {
+
+ case 1:
+ ending = "рубль";
+ break;
+ case 2:
+ case 3:
+ case 4:
+ ending = "рубля";
+ break;
+ default:
+ ending = "рублей";
+ }
+
+
+ }
}
+
+}
+
+class Product {
+ String productName;
+ double productPrice;
}
+
+
+
+
+
+
+
+
+