diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
new file mode 100644
index 0000000..1bec35e
--- /dev/null
+++ b/.idea/codeStyles/Project.xml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ 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..fb7f4a8
--- /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..ba1ec5c
--- /dev/null
+++ b/.idea/gradle.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..08a0d19
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ 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..1843428 100644
--- a/build.gradle
+++ b/build.gradle
@@ -1,6 +1,6 @@
apply plugin: 'java'
-sourceCompatibility = 1.8
+sourceCompatibility = 11
version = '1.0'
repositories {
@@ -8,3 +8,4 @@ repositories {
dependencies {
}
+targetCompatibility = JavaVersion.VERSION_11
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index a9198c4..d5f94f9 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -1,8 +1,12 @@
+import calculator.Calculator;
+
public class Main {
public static void main(String[] args) {
- // ваш код начнется здесь
- // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости
- System.out.println("Привет Мир");
+ Calculator calculator = new Calculator();
+
+ System.out.println("Добро пожаловать в приложение Калькулятор счета");
+ calculator.calculate();
+ System.out.println("Спасибо что выбрали наше приложение");
}
}
diff --git a/src/main/java/calculator/Calculator.java b/src/main/java/calculator/Calculator.java
new file mode 100644
index 0000000..eabfc41
--- /dev/null
+++ b/src/main/java/calculator/Calculator.java
@@ -0,0 +1,111 @@
+package calculator;
+
+import java.util.*;
+
+public class Calculator {
+ private final Scanner scanner = new Scanner(System.in);
+ private final List products = new ArrayList<>();
+
+ public void calculate() {
+ int numberOfPersons = addNumberOfPersons();
+ double sum = addProducts();
+ double result = sum / numberOfPersons;
+
+ printAllProducts();
+ printResult(result);
+ }
+
+ private int addNumberOfPersons() {
+ int numberOfPersons = 0;
+
+ System.out.println("Введите количество персон");
+
+ while (numberOfPersons < 2) {
+ if (!scanner.hasNextInt()) {
+ System.out.println("Вы ввели некорректное значение \nПопробуйте еще раз");
+ scanner.next();
+ } else {
+ numberOfPersons = scanner.nextInt();
+ if (numberOfPersons < 2) {
+ System.out.println("Количество персон должно быть более 1 \nПопробуйте еще раз");
+ }
+ }
+ }
+
+ return numberOfPersons;
+ }
+
+ private double addProducts() {
+ String exit = "Завершить";
+ double sumOfProducts = 0.0;
+
+ do {
+ String productTitle = addProductTitle();
+ double productPrice = addProductPrice();
+ Product product = new Product(productTitle, productPrice);
+ sumOfProducts += productPrice;
+
+ products.add(product);
+ System.out.println("Товар успешно добавлен");
+ System.out.println("Хотите добавить еще товар? " +
+ "\nЕсли да, то введите любой символ " +
+ "\nЕсли хотите завершить, то введите 'Завершить'");
+
+ } while (!scanner.next().equalsIgnoreCase(exit));
+
+ return sumOfProducts;
+ }
+
+ private String addProductTitle() {
+ System.out.println("Введите название товара");
+
+ return scanner.next();
+ }
+
+ private double addProductPrice() {
+ double price = 0.0;
+
+ System.out.println("Введите стоимость товара в формате 'рубли,копейки' [10,45, 11,40]");
+
+ while (price <= 0.01) {
+ if (!scanner.hasNextDouble()) {
+ System.out.println("Вы ввели некорректное значение " +
+ "\nВведите стоимость товара в формате 'рубли,копейки' [10,45, 11,40] " +
+ "\nПопробуйте еще раз");
+ scanner.next();
+ } else {
+ price = scanner.nextDouble();
+ if (price <= 0.0) {
+ System.out.println("Стоимость товара должна быть больше 0 \nПопробуйте еще раз");
+ }
+ }
+ }
+
+ return price;
+ }
+
+ private void printAllProducts() {
+ System.out.println("Добавленные товары:");
+
+ for (Product product : products) {
+ System.out.println(product.getTitle() + " : " + String.format("%.2f", product.getPrice()));
+ }
+ }
+
+ private void printResult(double price) {
+ String format = String.valueOf((int) price);
+ String result;
+
+ if (format.endsWith("11")) {
+ result = "рублей";
+ } else if (format.endsWith("1")) {
+ result = "рубль";
+ } else if (format.endsWith("2") || format.endsWith("3") || format.endsWith("4")) {
+ result = "рубля";
+ } else {
+ result = "рублей";
+ }
+
+ System.out.println("Сумма к оплате: " + String.format("%.2f", price) + " " + result);
+ }
+}
diff --git a/src/main/java/calculator/Product.java b/src/main/java/calculator/Product.java
new file mode 100644
index 0000000..01a5ef1
--- /dev/null
+++ b/src/main/java/calculator/Product.java
@@ -0,0 +1,19 @@
+package calculator;
+
+class Product {
+ private final String title;
+ private final double price;
+
+ public Product(String title, double price) {
+ this.title = title;
+ this.price = price;
+ }
+
+ String getTitle() {
+ return title;
+ }
+
+ double getPrice() {
+ return price;
+ }
+}