From e1f6893023e1e00e765909b127129a7ab6ece3d6 Mon Sep 17 00:00:00 2001 From: s-buvaka Date: 2022年7月27日 23:03:27 +0300 Subject: [PATCH 1/6] Remove classes --- src/main/java/Calculator.java | 22 ---------------- src/main/java/Formatter.java | 17 ------------- src/main/java/Item.java | 10 -------- src/main/java/Main.java | 47 +++-------------------------------- 4 files changed, 3 insertions(+), 93 deletions(-) delete mode 100644 src/main/java/Calculator.java delete mode 100644 src/main/java/Formatter.java delete mode 100644 src/main/java/Item.java diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java deleted file mode 100644 index 2fbc00d..0000000 --- a/src/main/java/Calculator.java +++ /dev/null @@ -1,22 +0,0 @@ -class Calculator { - - int friendsCount; - - String cart = "Добавленные товары:"; - double totalPrice = 0; - - Calculator(int friendsCount) { - this.friendsCount = friendsCount; - } - - void addItem(Item item) { - totalPrice += item.price; - cart = cart + "\n" + item.name; - - System.out.println(item.name + " в корзине"); - } - - double divideSum() { - return totalPrice / friendsCount; - } -} diff --git a/src/main/java/Formatter.java b/src/main/java/Formatter.java deleted file mode 100644 index 3f915b7..0000000 --- a/src/main/java/Formatter.java +++ /dev/null @@ -1,17 +0,0 @@ -public class Formatter { - - String formatValue(double price) { - double roundedValue = Math.floor(price); - if (roundedValue == 1) { - return "рубль"; - } else if (roundedValue>= 2 && roundedValue <= 4) { - return "рубля"; - } else { - return "рублей"; - } - } - - String roundResult(final double result) { - return String.format("%.2f", result); - } -} diff --git a/src/main/java/Item.java b/src/main/java/Item.java deleted file mode 100644 index fad8a4e..0000000 --- a/src/main/java/Item.java +++ /dev/null @@ -1,10 +0,0 @@ -class Item { - - String name; - double price; - - Item(String name, double price) { - this.name = name; - this.price = price; - } -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 11ba5d3..a9198c4 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,49 +1,8 @@ -import java.util.Scanner; - public class Main { public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); - - int friendCount; - while (true) { - System.out.println("На сколько человек необходимо разделить счет?"); - friendCount = scanner.nextInt(); - - if (friendCount> 1) { - break; - } else if (friendCount == 1) { - System.out.println( - "Нет смысла делить сумму на одного человека. Давайте попробуем ввести другое значение, которое будет больше единицы."); - } else { - System.out.println("Неверное количество друзей. Значение должно быть болье единицы, давайте попробуем еще раз."); - } - } - - Calculator calculator = new Calculator(friendCount); - - while (true) { - System.out.println("Введите название товара"); - String name = scanner.next(); - - System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [10.45, 11.40]"); - double price = scanner.nextDouble(); - - calculator.addItem(new Item(name, price)); - - System.out.println( - "Хотите добавить еще один товар? Введите любой символ для продолжения, либо 'Завершить' если больше нет товаров для добавления"); - String answer = scanner.next(); - - if (answer.equalsIgnoreCase("Завершить")) { - break; - } - } - - double result = calculator.divideSum(); - Formatter formatter = new Formatter(); - - System.out.println(calculator.cart); - System.out.println("Каждому человеку к оплате: " + formatter.roundResult(result) + " " + formatter.formatValue(result)); + // ваш код начнется здесь + // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости + System.out.println("Привет Мир"); } } From c521234c876be18b465b2fd45ef8a71d814fb7a9 Mon Sep 17 00:00:00 2001 From: s-buvaka Date: 2022年7月27日 23:13:52 +0300 Subject: [PATCH 2/6] Change project name --- settings.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/settings.gradle b/settings.gradle index 716abf2..be110bf 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,4 +12,4 @@ dependencyResolutionManagement { mavenCentral() } } -rootProject.name = "BillCalculator" +rootProject.name = "Java-Module-Project" From 2567102b1194abc14e82372bb7cba8a47e99a78d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: 2022年9月12日 10:55:03 +0500 Subject: [PATCH 3/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculate.java | 48 ++++++++++++++++++++++++++++++++++++ src/main/java/Main.java | 8 ------ src/main/java/Math.java | 19 ++++++++++++++ src/main/java/Menu.java | 30 ++++++++++++++++++++++ 4 files changed, 97 insertions(+), 8 deletions(-) create mode 100644 src/main/java/Calculate.java delete mode 100644 src/main/java/Main.java create mode 100644 src/main/java/Math.java create mode 100644 src/main/java/Menu.java diff --git a/src/main/java/Calculate.java b/src/main/java/Calculate.java new file mode 100644 index 0000000..cce2b05 --- /dev/null +++ b/src/main/java/Calculate.java @@ -0,0 +1,48 @@ + +import java.util.Scanner; + +public class Calculate { + + public static int product(double person) { + + String food = ""; + double price = 0.0; + String itog = ""; + + while (true) { + System.out.println("Для добавления товара введите название продукта\nДля завершения программы введите \"Завершить\""); + Scanner scanner = new Scanner(System.in); + + String inputFood = scanner.next(); + + if (inputFood.equals("Завершить")) { + + itog = String.format("%.2f", price / person); + System.out.println("Покупка завершена, " + String.format("%.0f", person) + " персоны заплатят по " + itog + " рублей"); + + } else { + System.out.println("Введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\""); + float inputPrice = (float) scanner.nextDouble(); + + food = food + "\n" + inputFood; + price = price + inputPrice; + System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " рублей"); + + + } + } + } +} + + + + + + + + + + + + + diff --git a/src/main/java/Main.java b/src/main/java/Main.java deleted file mode 100644 index a9198c4..0000000 --- a/src/main/java/Main.java +++ /dev/null @@ -1,8 +0,0 @@ -public class Main { - - public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); - } -} diff --git a/src/main/java/Math.java b/src/main/java/Math.java new file mode 100644 index 0000000..0691edd --- /dev/null +++ b/src/main/java/Math.java @@ -0,0 +1,19 @@ +public class Math { + + + public static void floor() { + double itog = 0; + int v = Calculate.product(itog); + + if (v == 0) { + System.out.println("рублей"); + } else if (v == 1) { + System.out.println("рублю"); + } else if (v == 2 || v == 3 || v == 4) { + System.out.println("рубля"); + } else if (v == 5 || v == 6 || v == 7 || v == 8 || v == 9) { + System.out.println("рублей"); + } + } +} + diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java new file mode 100644 index 0000000..01065f3 --- /dev/null +++ b/src/main/java/Menu.java @@ -0,0 +1,30 @@ +import java.util.Scanner; + +public class Menu { + public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + System.out.println("На сколько персон делить чек?"); + int person = scanner.nextInt(); + while (true) { + + if (person> 1) { + System.out.println("Давайте посчитаем!"); + Calculate.product(person); + } + if (person == 1) { + System.out.println("Вы оплачиваете счет сами"); + Calculate.product(person); + } + if (person < 1) { + System.out.println("Некорректное значение для подсчёта, попробуйте еще раз"); + break; + } + } + } +} + + + + + + From a590ea78f0ff1a59bfd88cba407657dd01d12281 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: 2022年9月12日 10:57:46 +0500 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D1=87=D0=B5=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=B7=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 + .idea/.name | 1 + .idea/codeStyles/Project.xml | 123 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/compiler.xml | 6 ++ .idea/gradle.xml | 18 ++++ .idea/misc.xml | 9 ++ .idea/vcs.xml | 6 ++ 8 files changed, 171 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml 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/.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 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 @@ + + + + + + + + + + \ 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..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 217b08c1ac3f4c78b5f0bbe5d948cfe1839ebda6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: 2022年9月13日 17:47:27 +0500 Subject: [PATCH 5/6] =?UTF-8?q?=D0=92=D0=BD=D0=B5=D1=81=20=D0=B8=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F,=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=BF=D0=BE=D0=B2=D1=82=D0=BE=D1=80=D0=BD=D1=83=D1=8E=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- src/main/java/Calculate.java | 51 ++++++++++++++++++++++-------------- src/main/java/Math.java | 19 -------------- src/main/java/Menu.java | 24 ++++++++++------- 4 files changed, 46 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/Math.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 5d10be7..64298bb 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/src/main/java/Calculate.java b/src/main/java/Calculate.java index cce2b05..684e71a 100644 --- a/src/main/java/Calculate.java +++ b/src/main/java/Calculate.java @@ -1,48 +1,59 @@ - import java.util.Scanner; public class Calculate { - public static int product(double person) { + public static void product(double person) { String food = ""; double price = 0.0; - String itog = ""; while (true) { System.out.println("Для добавления товара введите название продукта\nДля завершения программы введите \"Завершить\""); Scanner scanner = new Scanner(System.in); - String inputFood = scanner.next(); - if (inputFood.equals("Завершить")) { - itog = String.format("%.2f", price / person); - System.out.println("Покупка завершена, " + String.format("%.0f", person) + " персоны заплатят по " + itog + " рублей"); + double itog = 0; + if (inputFood.equalsIgnoreCase("Завершить")) { + itog = (int) (price / person); + System.out.println("Покупка завершена, " + String.format("%.0f", person) + " персоны заплатят по " + itog + " " + Matsh.floover(itog)); + break; } else { System.out.println("Введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\""); float inputPrice = (float) scanner.nextDouble(); food = food + "\n" + inputFood; - price = price + inputPrice; - System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " рублей"); + price = price + inputPrice; + System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " " + Matsh.floover(itog)); } } } -} - - - - - - - +} +class Matsh { + public static String floover(double itog){ - - - + int amount = (int) itog; + + if (amount> 100) + amount %= 100; + + if (amount> 20) + amount %= 10; + + switch (amount) { + case 1: + return "Рублю"; + case 2: + case 3: + case 4: + return "Рубля"; + default: + return "Рублей"; + } + } +} \ No newline at end of file diff --git a/src/main/java/Math.java b/src/main/java/Math.java deleted file mode 100644 index 0691edd..0000000 --- a/src/main/java/Math.java +++ /dev/null @@ -1,19 +0,0 @@ -public class Math { - - - public static void floor() { - double itog = 0; - int v = Calculate.product(itog); - - if (v == 0) { - System.out.println("рублей"); - } else if (v == 1) { - System.out.println("рублю"); - } else if (v == 2 || v == 3 || v == 4) { - System.out.println("рубля"); - } else if (v == 5 || v == 6 || v == 7 || v == 8 || v == 9) { - System.out.println("рублей"); - } - } -} - diff --git a/src/main/java/Menu.java b/src/main/java/Menu.java index 01065f3..86b6c0f 100644 --- a/src/main/java/Menu.java +++ b/src/main/java/Menu.java @@ -2,11 +2,20 @@ public class Menu { public static void main(String[] args) { +inputParameters(); + + } + public static void inputParameters(){ Scanner scanner = new Scanner(System.in); System.out.println("На сколько персон делить чек?"); - int person = scanner.nextInt(); - while (true) { + int person = 0; + while (!scanner.hasNextInt()) { + System.out.println("Некорректное значение для подсчёта, попробуйте еще раз"); + scanner.next(); + } + while (true) { + person = scanner.nextInt(); if (person> 1) { System.out.println("Давайте посчитаем!"); Calculate.product(person); @@ -17,14 +26,9 @@ public static void main(String[] args) { } if (person < 1) { System.out.println("Некорректное значение для подсчёта, попробуйте еще раз"); - break; + + } } } -} - - - - - - +} \ No newline at end of file From 545868e3a0fd4a5c057fe925c53be721867d9bb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9?= Date: 2022年9月14日 22:26:14 +0500 Subject: [PATCH 6/6] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=87=D1=82=D0=BE=20=D0=B1=D1=8B=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=20=D0=BC?= =?UTF-8?q?=D0=BE=D0=B3=20=D0=B2=D0=B2=D0=B5=D1=81=D1=82=D0=B8=20=D1=81?= =?UTF-8?q?=D1=82=D1=80=D0=BE=D0=BA=D1=83=20=D0=B8=20=D1=87=D0=B8=D1=81?= =?UTF-8?q?=D0=BB=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculate.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/Calculate.java b/src/main/java/Calculate.java index 684e71a..7f38391 100644 --- a/src/main/java/Calculate.java +++ b/src/main/java/Calculate.java @@ -11,9 +11,8 @@ public static void product(double person) { System.out.println("Для добавления товара введите название продукта\nДля завершения программы введите \"Завершить\""); Scanner scanner = new Scanner(System.in); String inputFood = scanner.next(); - - double itog = 0; + if (inputFood.equalsIgnoreCase("Завершить")) { itog = (int) (price / person); System.out.println("Покупка завершена, " + String.format("%.0f", person) + " персоны заплатят по " + itog + " " + Matsh.floover(itog)); @@ -21,10 +20,12 @@ public static void product(double person) { } else { System.out.println("Введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\""); + while (!scanner.hasNextInt()) { + System.out.println("Некорректное значение, введите стоимость продукта в формате \"'рубли.копейки' [10.45, 11.40]\""); + scanner.next(); + } float inputPrice = (float) scanner.nextDouble(); - food = food + "\n" + inputFood; - price = price + inputPrice; System.out.println("Вы успешно добавили продукт:" + food + "\nИтог: " + String.format("%.2f", price) + " " + Matsh.floover(itog)); @@ -32,12 +33,11 @@ public static void product(double person) { } } -} -class Matsh { +static class Matsh { + + public static String floover(double price) { - public static String floover(double itog){ - - int amount = (int) itog; + int amount = (int) price; if (amount> 100) amount %= 100; @@ -54,6 +54,7 @@ public static String floover(double itog){ return "Рубля"; default: return "Рублей"; + } } } } \ No newline at end of file

    AltStyle によって変換されたページ (->オリジナル) /