From 403e88a19d9a2a4d229d19657c61e2bea5797428 Mon Sep 17 00:00:00 2001 From: AndrewkaW Date: Wed, 26 Oct 2022 00:11:16 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D0=BA=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/List.java | 46 +++++++++++++++++++++++++++++++++++++++ src/main/java/Main.java | 7 +++--- src/main/java/People.java | 26 ++++++++++++++++++++++ 3 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 src/main/java/List.java create mode 100644 src/main/java/People.java diff --git a/src/main/java/List.java b/src/main/java/List.java new file mode 100644 index 0000000..f58ab59 --- /dev/null +++ b/src/main/java/List.java @@ -0,0 +1,46 @@ +import java.util.Scanner; + +public class List { + static double totalPrice = 0.00f; + static String listProduct = ""; + public static void requestProduct() { + Scanner scanner = new Scanner(System.in); + + while(true) { + + + System.out.println("Введите название товара"); + String name = scanner.next(); + listProduct = listProduct.concat(name + ";\n"); + System.out.println("Введите цену товара"); + double price = scanner.nextDouble(); + totalPrice =totalPrice + price; + System.out.println("Товар успешно добавлен!\nЕсли хотите добавить еще товар введите любой символ.\nДля завершения создания списка напините \"Завершить\"."); + String result = scanner.next(); + if(result.equalsIgnoreCase("Завершить")){ + break; + } + + } + + + } + public static String whichRub(double num){ + int sum = (int)num; + if(sum % 10 == 1 && sum != 11 && sum % 100 != 11){ + return "рубль"; + } + else if(sum % 10 >= 2 && sum % 10 <= 4 ){ + return "рубля"; + } + else{ + return "рублeй"; + } + } + public static void makeList() { + double priceForOne = totalPrice / People.persons; + String end = "Добавленные товары:\n%s%.2f %s должен заплатить каждый человек."; + System.out.println(String.format(end, listProduct, priceForOne,whichRub(priceForOne))); + } +} + diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..ec2ddfe 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,9 @@ public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + System.out.println("Привет!"); + People.howMany(); + List.requestProduct(); + List.makeList(); } } diff --git a/src/main/java/People.java b/src/main/java/People.java new file mode 100644 index 0000000..fef89a0 --- /dev/null +++ b/src/main/java/People.java @@ -0,0 +1,26 @@ +import java.util.Scanner; + +public class People { + + public static int persons; + + public static void howMany(){ + System.out.println("На скольких человек необходимо разделить счёт?"); + while(true) { + Scanner scanner = new Scanner(System.in); + boolean hasInt = scanner.hasNextInt(); + if(hasInt) { + int hasPersons = scanner.nextInt(); + if (hasPersons > 1) { + persons = hasPersons; + return; + } else { + System.out.println("Ошибка! Введите корректное число."); + } + } + else { + System.out.println("Ошибка! Введите корректное число."); + } + } + } +} From 7252dfda316b96a2b320d0091aae8828e57bae68 Mon Sep 17 00:00:00 2001 From: AndrewkaW Date: Wed, 26 Oct 2022 00:13:57 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=BC=D0=BA=D0=B0=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0?= 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 | 9 +++++++++ .idea/vcs.xml | 6 ++++++ 5 files changed, 42 insertions(+) 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 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..5d10be7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ 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 From 730b1588ac5cd9a50c8b5e743059badb37cfb82c Mon Sep 17 00:00:00 2001 From: AndrewkaW Date: Fri, 28 Oct 2022 02:23:36 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=A1=D0=BA=D0=BB=D0=BE=D0=BD=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=80=D1=83=D0=B1=D0=BB=D1=8F.=20=D0=94=D0=BE=D0=B1=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D0=BB=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20=D0=BF=D1=80=D0=B8=20=D0=B2?= =?UTF-8?q?=D0=B2=D0=BE=D0=B4=D0=B5=20=D0=BD=D0=B5=D0=BA=D0=BE=D1=80=D1=80?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BD=D0=BE=D0=B9=20=D1=86=D0=B5=D0=BD=D1=8B?= =?UTF-8?q?.=20=D0=A3=D1=87=D0=B5=D0=BB=20=D0=BA=D0=BE=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0=D1=80=D0=B8=D0=B8=20=D0=B2=20PR.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/List.java | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/main/java/List.java b/src/main/java/List.java index f58ab59..3f8c792 100644 --- a/src/main/java/List.java +++ b/src/main/java/List.java @@ -13,8 +13,8 @@ public static void requestProduct() { String name = scanner.next(); listProduct = listProduct.concat(name + ";\n"); System.out.println("Введите цену товара"); - double price = scanner.nextDouble(); - totalPrice =totalPrice + price; + double price = checkFailPrice(); + totalPrice += price; System.out.println("Товар успешно добавлен!\nЕсли хотите добавить еще товар введите любой символ.\nДля завершения создания списка напините \"Завершить\"."); String result = scanner.next(); if(result.equalsIgnoreCase("Завершить")){ @@ -24,23 +24,44 @@ public static void requestProduct() { } - } + } public static String whichRub(double num){ int sum = (int)num; - if(sum % 10 == 1 && sum != 11 && sum % 100 != 11){ - return "рубль"; - } - else if(sum % 10 >= 2 && sum % 10 <= 4 ){ - return "рубля"; - } - else{ + sum = sum % 100; + if(10 0) { + return trueDouble; + } else { + System.out.println("Ошибка! Введите корректную цену."); + } + } + else { + System.out.println("Ошибка! Введите корректную цену."); + } + } + } }