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/git_toolbox_prj.xml b/.idea/git_toolbox_prj.xml
new file mode 100644
index 0000000..02b915b
--- /dev/null
+++ b/.idea/git_toolbox_prj.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+
+
+
+
+
\ 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..2de2ef6 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,8 +1,83 @@
-public class Main {
+import java.util.Scanner;
+public class Main {
+ private static final Scanner scan = new Scanner(System.in);
public static void main(String[] args) {
- // ваш код начнется здесь
- // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
- System.out.println("Привет Мир");
+ Calculator.inputPersons();
+ Calculator.addProducts();
+ Calculator.payPeople();
+ }
+
+ public static class Calculator {
+ static double totalPrice = 0;
+ static String names = "";
+ static int persons = 0;
+
+ public static void inputPersons() {
+ while (true) {
+ System.out.println("How many persons?");
+ if (scan.hasNextInt()) {
+ persons = scan.nextInt();
+ if (persons <= 1) { + System.out.println("Amount of persons must be integer> 1. Try again.");
+ continue;
+ }
+ break;
+ } else {
+ System.out.println("Amount of persons must be integer> 1. Try again.");
+ scan.nextLine();
+ continue;
+ }
+ }
+ }
+
+ public static void addProducts() {
+ while (true) {
+ System.out.println("Product name: ");
+ String name = scan.next() + scan.nextLine();
+ System.out.println("Price: ");
+ if (scan.hasNextDouble()) {
+ double price = scan.nextDouble();
+ if (price < 0) {
+ System.out.println("Price must be positive double! Try again");
+ continue;
+ }
+ totalPrice += price;
+ names += name + "\n";
+ } else {
+ System.out.println("Price must be positive double! Try again");
+ scan.nextLine();
+ continue;
+ }
+ System.out.println("Product " + name + " successfully added! Enough? (yes - any symbol/no - n): ");
+ String answer = scan.next();
+ if (answer.equalsIgnoreCase("n")) {
+ continue;
+ } else {break;}
+ }
+ }
+
+ public static void payPeople() {
+ int ruble = (int) Math.floor(totalPrice);
+ int payPeople = (int) Math.floor(totalPrice/persons);
+ System.out.println("Вы заказали следующие продукты:\n" + names + "на сумму: " + totalPrice + " " + Calculator.payPeoples(ruble));
+ System.out.println("Каждый из " + persons + " человек заплатит по " + String.format("%.2f", totalPrice/persons) + " " + Calculator.payPeoples(payPeople));
+ }
+
+ static String payPeoples(int ruble) {
+ if (ruble % 100 / 10 == 1) {
+ return "рублей";
+ } else {
+ switch (ruble % 10) {
+ case 1 :
+ return "рубль";
+ case 2:
+ case 3:
+ case 4:
+ return "рубля";
+ default: return "рублей";
+ }
+ }
+ }
}
-}
+}
\ No newline at end of file