From 5a2609a0cfde586137810c361dbc7f85a6b9cae2 Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 1 Dec 2022 20:34:56 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9B=D0=B0=D0=B1.=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=201.=20=D0=AF?= =?UTF-8?q?=D0=BD=20=D1=86=D0=B0=D0=B1=D1=83=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 20 ++++++++++++++ src/main/java/Main.java | 22 +++++++++++++-- src/main/java/Products.java | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Calculator.java create mode 100644 src/main/java/Products.java diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java new file mode 100644 index 0000000..187c0ef --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,20 @@ +public class Calculator { + public static String complete(float costGeneral) { + String suffix; + int hundred = (int) Math.floor(costGeneral % 100); + if (hundred <= 14 && hundred>= 11) { + suffix = " рублей "; + } else { + int ten = hundred % 10; + if (ten == 1) { + suffix = " рубль "; + } else if (ten>= 2 && ten <= 4) { + suffix = " рубля "; + } else { + suffix = " рублей "; + } + + } + return suffix; + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..71429cd 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,26 @@ +import java.util.Scanner; + public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости System.out.println("Привет Мир"); + System.out.println("Вас приветствует Калькулятор - счётчик"); + Scanner scanner1 = new Scanner(System.in); + int people; + while (true) { + System.out.println("На сколько людей разделить счет?"); + if (scanner1.hasNextInt()) { + people = scanner1.nextInt(); + if (people == 1) { + System.out.println("Нет смысла делить счёт на одного. Введите корректное значение гостей."); + } else if (people < 1) { + System.out.println("Вы ввели некоректное значение. Количество гостей должно быть больше одного. Попробуйте ещё раз."); + } else { + break; + } + } + } + Products.calc(people); } } + diff --git a/src/main/java/Products.java b/src/main/java/Products.java new file mode 100644 index 0000000..b4ac0de --- /dev/null +++ b/src/main/java/Products.java @@ -0,0 +1,50 @@ +import java.util.Scanner; + +public class Products { + static String exit = "ЗАВЕРШИТЬ"; + + public static void calc(int people) { + String product; + String allProducts = ""; + float costPrice; + float sumForall = 0.00f; + + String close; + while (true) { + Scanner scanner2 = new Scanner(System.in); + System.out.println("Введите название товара"); + product = scanner2.nextLine(); + System.out.println("Товар " + product + " добавлен в счёт"); + System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [пример - 10.45, 11.40]"); + if (scanner2.hasNextFloat()) { + costPrice = scanner2.nextFloat(); + if (costPrice> 0) { + sumForall = sumForall + costPrice; + allProducts = allProducts + product + "\n"; + String sufForOne = Calculator.complete(costPrice); + String anotherOne = "Вы добавили: %s за %.2f%s\n"; + System.out.printf(anotherOne, product, costPrice, sufForOne); + System.out.println("Введите любой символ, если хотите добавить товар. В противном случае введите:'ЗАВЕРШИТЬ'"); + close = scanner2.next(); + if (close.equalsIgnoreCase(exit)) { + break; + } + } else { + System.out.println("Сумма указана неверно"); + } + } else { + System.out.println("Некорректный формат стоимости товара. Побробуйте ввести сумму ещё раз!"); + } + + } + String suf = Calculator.complete(sumForall); + float forOneguest = sumForall/ people; + String lastSuf = Calculator.complete(forOneguest); + + System.out.println("Вы купили:\n" + allProducts + "За " + String.format("%.2f", sumForall) + suf); + System.out.println("Каждый из гостей должен заплатить: " + String.format("%.2f", forOneguest) + lastSuf); + System.out.println("Спасибо,что воспользовались нашим Калькулятором - счётчиком!"); + + + } +} \ No newline at end of file From 9316f14e020d7b9833fbde3d727ff590e689e4c2 Mon Sep 17 00:00:00 2001 From: yan Date: Thu, 1 Dec 2022 20:34:56 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9B=D0=B0=D0=B1.=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=201.=20=D0=AF?= =?UTF-8?q?=D0=BD=20=D1=86=D0=B0=D0=B1=D1=83=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 20 ++++++++++++++ src/main/java/Main.java | 22 +++++++++++++-- src/main/java/Products.java | 50 +++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 src/main/java/Calculator.java create mode 100644 src/main/java/Products.java diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java new file mode 100644 index 0000000..187c0ef --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,20 @@ +public class Calculator { + public static String complete(float costGeneral) { + String suffix; + int hundred = (int) Math.floor(costGeneral % 100); + if (hundred <= 14 && hundred>= 11) { + suffix = " рублей "; + } else { + int ten = hundred % 10; + if (ten == 1) { + suffix = " рубль "; + } else if (ten>= 2 && ten <= 4) { + suffix = " рубля "; + } else { + suffix = " рублей "; + } + + } + return suffix; + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..71429cd 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,26 @@ +import java.util.Scanner; + public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости System.out.println("Привет Мир"); + System.out.println("Вас приветствует Калькулятор - счётчик"); + Scanner scanner1 = new Scanner(System.in); + int people; + while (true) { + System.out.println("На сколько людей разделить счет?"); + if (scanner1.hasNextInt()) { + people = scanner1.nextInt(); + if (people == 1) { + System.out.println("Нет смысла делить счёт на одного. Введите корректное значение гостей."); + } else if (people < 1) { + System.out.println("Вы ввели некоректное значение. Количество гостей должно быть больше одного. Попробуйте ещё раз."); + } else { + break; + } + } + } + Products.calc(people); } } + diff --git a/src/main/java/Products.java b/src/main/java/Products.java new file mode 100644 index 0000000..b4ac0de --- /dev/null +++ b/src/main/java/Products.java @@ -0,0 +1,50 @@ +import java.util.Scanner; + +public class Products { + static String exit = "ЗАВЕРШИТЬ"; + + public static void calc(int people) { + String product; + String allProducts = ""; + float costPrice; + float sumForall = 0.00f; + + String close; + while (true) { + Scanner scanner2 = new Scanner(System.in); + System.out.println("Введите название товара"); + product = scanner2.nextLine(); + System.out.println("Товар " + product + " добавлен в счёт"); + System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [пример - 10.45, 11.40]"); + if (scanner2.hasNextFloat()) { + costPrice = scanner2.nextFloat(); + if (costPrice> 0) { + sumForall = sumForall + costPrice; + allProducts = allProducts + product + "\n"; + String sufForOne = Calculator.complete(costPrice); + String anotherOne = "Вы добавили: %s за %.2f%s\n"; + System.out.printf(anotherOne, product, costPrice, sufForOne); + System.out.println("Введите любой символ, если хотите добавить товар. В противном случае введите:'ЗАВЕРШИТЬ'"); + close = scanner2.next(); + if (close.equalsIgnoreCase(exit)) { + break; + } + } else { + System.out.println("Сумма указана неверно"); + } + } else { + System.out.println("Некорректный формат стоимости товара. Побробуйте ввести сумму ещё раз!"); + } + + } + String suf = Calculator.complete(sumForall); + float forOneguest = sumForall/ people; + String lastSuf = Calculator.complete(forOneguest); + + System.out.println("Вы купили:\n" + allProducts + "За " + String.format("%.2f", sumForall) + suf); + System.out.println("Каждый из гостей должен заплатить: " + String.format("%.2f", forOneguest) + lastSuf); + System.out.println("Спасибо,что воспользовались нашим Калькулятором - счётчиком!"); + + + } +} \ No newline at end of file From 3b8a936e9fe5514bede458ff1c6f8e7933aa0cb0 Mon Sep 17 00:00:00 2001 From: yan Date: Sun, 4 Dec 2022 21:19:03 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=9B=D0=B0=D0=B1.=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5?= =?UTF-8?q?=D1=80=D0=BA=D1=83=20=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=201.=20?= =?UTF-8?q?=D0=AF=D0=BD=20=D1=86=D0=B0=D0=B1=D1=83=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 + .idea/codeStyles/Project.xml | 123 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/compiler.xml | 6 ++ .idea/gradle.xml | 18 ++++ .idea/misc.xml | 10 +++ .idea/vcs.xml | 6 ++ 7 files changed, 171 insertions(+) create mode 100644 .idea/.gitignore 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/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..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

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