From 867ede783fd44708d4c2b9a80a6423f0b12c012b Mon Sep 17 00:00:00 2001 From: SergeyNoskov2022 Date: Thu, 3 Nov 2022 20:31:02 +0500 Subject: [PATCH 1/4] =?UTF-8?q?=D0=BD=D0=B5=20=D1=81=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=88=D0=B5=D0=BD=D0=BD=D0=BE,=20=D0=BD=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82.=20=D0=9D=D0=B5=20?= =?UTF-8?q?=D0=B4=D1=8B=D1=88=D0=B8=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 ++ .idea/compiler.xml | 6 +++ .idea/gradle.xml | 18 +++++++++ .idea/misc.xml | 10 +++++ .idea/vcs.xml | 6 +++ src/main/java/Calculate.java | 72 ++++++++++++++++++++++++++++++++++++ src/main/java/Main.java | 18 ++++++--- 7 files changed, 128 insertions(+), 5 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/Calculate.java 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/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/Calculate.java b/src/main/java/Calculate.java new file mode 100644 index 0000000..595f10b --- /dev/null +++ b/src/main/java/Calculate.java @@ -0,0 +1,72 @@ +import java.util.Scanner; +public class Calculate { + int guest; + String totalName = ""; + double totalPrice = 0.00f; + String rub = ""; + Scanner scanner = new Scanner(System.in); + + + public void addGuests() { + while (true) { + System.out.println("Введите количество человек в вашей компании:"); + if (scanner.hasNextInt()) { + guest = scanner.nextInt(); + if (guest > 1) { + System.out.println("Спасибо! Разделим счёт на " + guest + " человек(а)\nПриступим к заполнению заказа."); + break;// + } else { + System.out.println("Некорректное значение гостей, попробуйте снова!"); + } + } else { + System.out.println("Ожидается ввод числового значения, попробуйте снова!"); + scanner.nextLine(); + } + } + } + public void sumProducts() { + + while (true) { + System.out.println("Введите название товара:"); + String name = scanner.next(); + String cancel = "Завершить"; + boolean check = cancel.equalsIgnoreCase(name); + if (check) { + System.out.println("Ваш заказ: " + "\n" + totalName); + System.out.println("На общую стоимость: " + totalPrice + " руб."); + break; + } else { + totalName = totalName + name + "\n"; + System.out.println("Введите стоимость товара (рубли,копейки):"); + if (scanner.hasNextDouble()) { + double price = scanner.nextDouble(); + totalPrice = totalPrice + price; + System.out.println("Спасибо! Ваш товар добавлен в заказ!"); + } else { + System.out.println("Ожидается ввод числового значения, попробуйте снова!"); + } + + } + } + + } + public void divTotalPrice() { + int lastNum = (int) totalPrice % 10; + + if (totalPrice % 100 >= 11 && totalPrice % 100 <= 20) { + rub = "рублей"; + } else if (lastNum > 1 && lastNum < 5) { + rub = "рубля"; + } else if (totalPrice % 10 == 1) { + rub = "рубль"; + } + else { + rub = "рублей"; + } + + double guestSum = totalPrice / (double)guest; + System.out.println("Каждый гость должен заплатить по " + String.format("%.2f", guestSum) + " " + rub + ".\nВсего доброго!"); + + } + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..6fa250c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,16 @@ +import java.util.Scanner; public class Main { - public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + Calculate calculate = new Calculate(); + calculate.addGuests(); + calculate.sumProducts(); + calculate.divTotalPrice(); + + + + } -} + + + +} \ No newline at end of file From 23aa474ea7597a4c30efaf3ccfffcbce8025686f Mon Sep 17 00:00:00 2001 From: SergeyNoskov2022 Date: Thu, 3 Nov 2022 20:34:13 +0500 Subject: [PATCH 2/4] =?UTF-8?q?=D0=BD=D0=B5=20=D1=81=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D1=88=D0=B5=D0=BD=D0=BD=D0=BE,=20=D0=BD=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82.=20=D0=9D=D0=B5=20?= =?UTF-8?q?=D0=B4=D1=8B=D1=88=D0=B8=D0=BC.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.name | 1 + 1 file changed, 1 insertion(+) create mode 100644 .idea/.name diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..962e712 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +Java-Module-Project \ No newline at end of file From 85d220be14c331886e6538652e93db4a79736370 Mon Sep 17 00:00:00 2001 From: SergeyNoskov2022 Date: Thu, 3 Nov 2022 23:31:27 +0500 Subject: [PATCH 3/4] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5?= =?UTF-8?q?=D1=82.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculate.java | 37 ++++++++++++++++++------------------ src/main/java/Main.java | 7 ------- 2 files changed, 19 insertions(+), 25 deletions(-) diff --git a/src/main/java/Calculate.java b/src/main/java/Calculate.java index 595f10b..36d7c4f 100644 --- a/src/main/java/Calculate.java +++ b/src/main/java/Calculate.java @@ -25,7 +25,6 @@ public void addGuests() { } } public void sumProducts() { - while (true) { System.out.println("Введите название товара:"); String name = scanner.next(); @@ -38,35 +37,37 @@ public void sumProducts() { } else { totalName = totalName + name + "\n"; System.out.println("Введите стоимость товара (рубли,копейки):"); - if (scanner.hasNextDouble()) { - double price = scanner.nextDouble(); - totalPrice = totalPrice + price; - System.out.println("Спасибо! Ваш товар добавлен в заказ!"); - } else { - System.out.println("Ожидается ввод числового значения, попробуйте снова!"); + while (true) { + if (scanner.hasNextDouble()) { + double price = scanner.nextDouble(); + if (price > 0) { + totalPrice = totalPrice + price; + System.out.println("Спасибо! Ваш товар добавлен в заказ!"); + break; + } else { + System.out.println("Некорректное значение цены, попробуйте снова!"); + } + } else { + System.out.println("Ожидается ввод числового значения, попробуйте снова!"); + scanner.next(); + } } - } } - } + public void divTotalPrice() { int lastNum = (int) totalPrice % 10; - if (totalPrice % 100 >= 11 && totalPrice % 100 <= 20) { rub = "рублей"; - } else if (lastNum > 1 && lastNum < 5) { + } else if (lastNum > 1 && lastNum < 5) { rub = "рубля"; - } else if (totalPrice % 10 == 1) { + } else if (totalPrice % 10 == 1) { rub = "рубль"; - } - else { + } else { rub = "рублей"; } - double guestSum = totalPrice / (double)guest; - System.out.println("Каждый гость должен заплатить по " + String.format("%.2f", guestSum) + " " + rub + ".\nВсего доброго!"); - + System.out.println("Сумма заказа на каждого гостя составила " + String.format("%.2f", guestSum) + " " + rub + ".\nЖдём Вас у нас снова!"); } - } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 6fa250c..1e9a4a1 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,4 +1,3 @@ -import java.util.Scanner; public class Main { public static void main(String[] args) { Calculate calculate = new Calculate(); @@ -6,11 +5,5 @@ public static void main(String[] args) { calculate.sumProducts(); calculate.divTotalPrice(); - - - } - - - } \ No newline at end of file From a576a97bbe5cf4a3516a676765d5469c0dfe3b02 Mon Sep 17 00:00:00 2001 From: SergeyNoskov2022 Date: Fri, 4 Nov 2022 23:44:00 +0500 Subject: [PATCH 4/4] =?UTF-8?q?=D0=A1=D0=BF=D0=B0=D1=81=D0=B8=D0=B1=D0=BE?= =?UTF-8?q?=20=D0=B7=D0=B0=20=D0=BA=D1=80=D0=B8=D1=82=D0=B8=D0=BA=D1=83!?= =?UTF-8?q?=20=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8=D0=BB.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculate.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/Calculate.java b/src/main/java/Calculate.java index 36d7c4f..33e944c 100644 --- a/src/main/java/Calculate.java +++ b/src/main/java/Calculate.java @@ -26,7 +26,7 @@ public void addGuests() { } public void sumProducts() { while (true) { - System.out.println("Введите название товара:"); + System.out.println("Введите название товара:\nЧтобы закончить ввод, введите 'Завершить'"); String name = scanner.next(); String cancel = "Завершить"; boolean check = cancel.equalsIgnoreCase(name); @@ -57,17 +57,17 @@ public void sumProducts() { } public void divTotalPrice() { - int lastNum = (int) totalPrice % 10; + double guestSum = totalPrice / (double)guest; + int lastNum = (int) guestSum % 10; if (totalPrice % 100 >= 11 && totalPrice % 100 <= 20) { rub = "рублей"; } else if (lastNum > 1 && lastNum < 5) { rub = "рубля"; - } else if (totalPrice % 10 == 1) { + } else if (lastNum % 10 == 1) { rub = "рубль"; } else { rub = "рублей"; } - double guestSum = totalPrice / (double)guest; System.out.println("Сумма заказа на каждого гостя составила " + String.format("%.2f", guestSum) + " " + rub + ".\nЖдём Вас у нас снова!"); } }