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/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..7643783
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,123 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xmlns:android
+
+ ^$
+
+
+
+
+
+
+
+
+ xmlns:.*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*:id
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ .*:name
+
+ http://schemas.android.com/apk/res/android
+
+
+
+
+
+
+
+
+ name
+
+ ^$
+
+
+
+
+
+
+
+
+ style
+
+ ^$
+
+
+
+
+
+
+
+
+ .*
+
+ ^$
+
+
+ BY_NAME
+
+
+
+
+
+
+ .*
+
+ http://schemas.android.com/apk/res/android
+
+
+ ANDROID_ATTRIBUTE_ORDER
+
+
+
+
+
+
+ .*
+
+ .*
+
+
+ BY_NAME
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml
new file mode 100644
index 0000000..79ee123
--- /dev/null
+++ b/.idea/codeStyles/codeStyleConfig.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
\ 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/build.gradle b/build.gradle
index 1b1d075..ce37dd3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -8,3 +8,10 @@ repositories {
dependencies {
}
+
+if (hasProperty('buildScan')) {
+ buildScan {
+ termsOfServiceUrl = 'https://gradle.com/terms-of-service'
+ termsOfServiceAgree = 'yes'
+ }
+}
\ No newline at end of file
diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java
new file mode 100644
index 0000000..a848d28
--- /dev/null
+++ b/src/main/java/Calculator.java
@@ -0,0 +1,75 @@
+import java.util.Scanner;
+
+public class Calculator {
+
+ static Scanner scanner = new Scanner(System.in);
+ static String userInput = null;
+ static String productName;
+ static String allProductsList = "Добавленные товары:";
+ static float productCost = 0.0F;
+ static float allProductsCost = 0.0F;
+ static float personalAmount = 0.0F;
+ static String checkedNumber = null;
+
+ static void printResult(int numberOfGuests) {
+ while (!"ЗАВЕРШИТЬ".equalsIgnoreCase(userInput)) {// цикл продолжается до ввода слова "заврешить" игнорируя регистр букв
+ System.out.println("Введите название товара и его цену.\nТовар: ");
+ productName = scanner.next();
+ allProductsList = allProductsList + "\n" + productName;
+ System.out.println("Введите стоимость: ");
+ checkedNumber = scanner.next();
+
+ while (true) {// цикл проверяет число ли ввёл пользователь и не является ли оно отрицательным
+ if (!isItaNumber(checkedNumber)) {
+ System.out.println("Бип, ошибка. Это не число, либо вы в качестве делителя используете запятую вместо точки.\nПопробуйте ещё раз. Введите цену: ");
+ checkedNumber = scanner.next();
+ } else if (!isItPositive(productCost = Float.parseFloat(checkedNumber))) {
+ System.out.println("Бип, ошибка. Цена не может быть отрицательной!\nПопробуйте ещё раз. Введите цену: ");
+ checkedNumber = scanner.next();
+ } else {
+
+ break;
+ }
+ }
+
+ allProductsCost += productCost;
+ System.out.println("Вы успешно добавили " + productName + " за " + String.format("%.2f", productCost) + " рублей.\nЕсли хотите завершить, наберите \"Завершить\" и нажмите \"enter\".\nЕсли хотите добавить ещё один товар, введите любой символ или слово и нажмите \"enter\".");
+ userInput = scanner.next();
+ }
+ String rubleEnding = getRubleEnding((int) Math.floor(allProductsCost)); // выясняем верное окончание слова "рубль" для общей суммы заказа
+ System.out.println(allProductsList + "\nОбщая сумма: " + String.format("%.2f", allProductsCost) + rubleEnding);
+ personalAmount = allProductsCost / numberOfGuests;
+ String personalRubleEnding = getRubleEnding((int) Math.floor(personalAmount));// выясняем верное окончание слова "рубль" для суммы отдельного гостя
+ System.out.println("Каждому гостю необходимо заплатить: " + String.format("%.2f", personalAmount) + personalRubleEnding);
+
+ }
+
+
+ private static boolean isItPositive(float productCost) {// проверяем не является ли число отрицательным
+ return productCost >= 0;
+ }
+
+ private static boolean isItaNumber(String checkedNumber) {// проверяем число ли ввёл пользователь
+
+ return checkedNumber.matches("-?\\d+(\\.\\d+)?");
+ }
+
+ public static String getRubleEnding(int wholeRubles) {// подбираем правльное окончание слову "рубль"
+ int preLastDigit = wholeRubles % 100 / 10;
+ if (preLastDigit == 1) {
+ return " рублей.";
+ } else {
+
+ switch (wholeRubles % 10) {
+ case 1:
+ return " рубль.";
+ case 2:
+ case 3:
+ case 4:
+ return " рубля.";
+ default:
+ return " рублей.";
+ }
+ }
+ }
+}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index a9198c4..b06ecbe 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,8 +1,27 @@
+import java.util.Scanner;
+
public class Main {
public static void main(String[] args) {
- // ваш код начнется здесь
- // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
- System.out.println("Привет Мир");
+
+ int numberOfGuests = getNumberOfGuests();
+ Calculator.printResult(numberOfGuests);
+
+ }
+
+ static int getNumberOfGuests() {
+ Scanner scanner = new Scanner(System.in);
+ while (true) {
+ System.out.println("Введите количество гостей.");
+ int number = scanner.nextInt();
+ if (number == 1) {
+ System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт.");
+ } else if (number < 2) {
+ System.out.println("Количество гостей не может быть меньше 1. Вероятно вы ошиблись.");
+ } else {
+ return number;
+ }
+
+ }
}
}