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..aa1559a
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,17 @@
+
+
+
+
+
+
\ 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..9b99d0f
--- /dev/null
+++ b/src/main/java/Calculator.java
@@ -0,0 +1,42 @@
+public class Calculator {
+
+ String bill = "";
+ double finalPrice = 0;
+ int countPerson = 0;
+
+ double priceOfPerson = 0;
+
+ public void setCountPerson(int countPerson) {
+ this.countPerson = countPerson;
+ }
+
+ public void setBill(Product product) {
+ bill += (product.getNameOfProduct() + " " + product.getCost()) + "\n";
+ finalPrice += product.getCost();
+ }
+
+ public String math() {
+ String rubles = "руб";
+ if (priceOfPerson > 10 && priceOfPerson <20 ) {
+ return rubles + "лей";
+ } switch ((int) priceOfPerson % 10) {
+ case 1: {
+ return rubles + "ль";
+ }
+ case 2:
+ case 3:
+ case 4: {
+ return rubles + "ля";
+ }
+ default: {
+ return rubles + "лей";
+ }
+ }
+ }
+
+ public void calculate() {
+ priceOfPerson = finalPrice / countPerson;
+ System.out.println("Количество персон: " + countPerson + "\n" + "Общий чек: " +
+ "\n" + bill + "\n" + "Денег с человека:" + "\n" + String.format("%.2f", priceOfPerson) + " " + math());
+ }
+}
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index a9198c4..a104a17 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,8 +1,54 @@
-public class Main {
+import java.util.InputMismatchException;
+import java.util.Scanner;
+public class Main {
+ static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
- // ваш код начнется здесь
- // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
- System.out.println("Привет Мир");
+
+
+ Calculator calculator = new Calculator();
+ System.out.println("На скольких человек разделить счет?");
+ int scanPerson;
+
+ while (true) {
+
+ if (scanner.hasNextInt()) {
+ scanPerson = scanner.nextInt();
+ if (scanPerson == 1) {
+ System.out.println("Подсчет не нужен");
+ System.exit(0);
+ } else if (scanPerson < 1) {
+ System.out.println("Ошибка. Введите корректное значение.");
+ } else break;
+ } else {
+ System.out.println("Введите корректное значение");
+ scanner.nextLine();
+ }
+ }
+
+ calculator.setCountPerson(scanPerson);
+ do {
+ Product product = new Product();
+ System.out.println("Введите название товара");
+ scanner.nextLine();
+ product.setNameOfProduct(scanner.nextLine());
+ System.out.println("Введите стоимость товара в формате 00,00");
+ product.setCost(inputPrice());
+ calculator.setBill(product);
+ System.out.println("Завершить? Нажмите любой символ, чтобы продолжить");
+ } while (!scanner.next().equalsIgnoreCase("Завершить"));
+ calculator.calculate();
+
+ }
+
+ static double price = 0.0;
+ public static double inputPrice() {
+ try {
+ price = scanner.nextDouble();
+ } catch (InputMismatchException exception) {
+ System.out.println("Введите корректное значение");
+ scanner.nextLine();
+ inputPrice();
+ } return price;
}
}
diff --git a/src/main/java/Product.java b/src/main/java/Product.java
new file mode 100644
index 0000000..a353d0a
--- /dev/null
+++ b/src/main/java/Product.java
@@ -0,0 +1,23 @@
+public class Product {
+
+ private String nameOfProduct;
+ private double cost;
+
+
+ public String getNameOfProduct() {
+ return nameOfProduct;
+ }
+
+ public void setNameOfProduct(String nameOfProduct) {
+ this.nameOfProduct = nameOfProduct;
+ }
+
+ public double getCost() {
+ return cost;
+ }
+
+ public void setCost(double cost) {
+ this.cost = cost;
+ }
+
+}