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/src/main/java/Calculator.java b/src/main/java/Calculator.java
new file mode 100644
index 0000000..187c0ef
--- /dev/null
+++ b/src/main/java/Calculator.java
@@ -0,0 +1,20 @@
+public class Calculator {
+ public static String complete(float costGeneral) {
+ String suffix;
+ int hundred = (int) Math.floor(costGeneral % 100);
+ if (hundred <= 14 && hundred>= 11) {
+ suffix = " рублей ";
+ } else {
+ int ten = hundred % 10;
+ if (ten == 1) {
+ suffix = " рубль ";
+ } else if (ten>= 2 && ten <= 4) { + suffix = " рубля "; + } else { + suffix = " рублей "; + } + + } + return suffix; + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..71429cd 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,26 @@ +import java.util.Scanner; + public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости System.out.println("Привет Мир"); + System.out.println("Вас приветствует Калькулятор - счётчик"); + Scanner scanner1 = new Scanner(System.in); + int people; + while (true) { + System.out.println("На сколько людей разделить счет?"); + if (scanner1.hasNextInt()) { + people = scanner1.nextInt(); + if (people == 1) { + System.out.println("Нет смысла делить счёт на одного. Введите корректное значение гостей."); + } else if (people < 1) { + System.out.println("Вы ввели некоректное значение. Количество гостей должно быть больше одного. Попробуйте ещё раз."); + } else { + break; + } + } + } + Products.calc(people); } } + diff --git a/src/main/java/Products.java b/src/main/java/Products.java new file mode 100644 index 0000000..b4ac0de --- /dev/null +++ b/src/main/java/Products.java @@ -0,0 +1,50 @@ +import java.util.Scanner; + +public class Products { + static String exit = "ЗАВЕРШИТЬ"; + + public static void calc(int people) { + String product; + String allProducts = ""; + float costPrice; + float sumForall = 0.00f; + + String close; + while (true) { + Scanner scanner2 = new Scanner(System.in); + System.out.println("Введите название товара"); + product = scanner2.nextLine(); + System.out.println("Товар " + product + " добавлен в счёт"); + System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [пример - 10.45, 11.40]"); + if (scanner2.hasNextFloat()) { + costPrice = scanner2.nextFloat(); + if (costPrice> 0) {
+ sumForall = sumForall + costPrice;
+ allProducts = allProducts + product + "\n";
+ String sufForOne = Calculator.complete(costPrice);
+ String anotherOne = "Вы добавили: %s за %.2f%s\n";
+ System.out.printf(anotherOne, product, costPrice, sufForOne);
+ System.out.println("Введите любой символ, если хотите добавить товар. В противном случае введите:'ЗАВЕРШИТЬ'");
+ close = scanner2.next();
+ if (close.equalsIgnoreCase(exit)) {
+ break;
+ }
+ } else {
+ System.out.println("Сумма указана неверно");
+ }
+ } else {
+ System.out.println("Некорректный формат стоимости товара. Побробуйте ввести сумму ещё раз!");
+ }
+
+ }
+ String suf = Calculator.complete(sumForall);
+ float forOneguest = sumForall/ people;
+ String lastSuf = Calculator.complete(forOneguest);
+
+ System.out.println("Вы купили:\n" + allProducts + "За " + String.format("%.2f", sumForall) + suf);
+ System.out.println("Каждый из гостей должен заплатить: " + String.format("%.2f", forOneguest) + lastSuf);
+ System.out.println("Спасибо,что воспользовались нашим Калькулятором - счётчиком!");
+
+
+ }
+}
\ No newline at end of file