From 57e717d870498ecf7e610c77d04053ece86a75f4 Mon Sep 17 00:00:00 2001 From: Djsdriver Date: 2022年10月25日 11:36:45 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=BA=D1=82=D0=B8=D1=87?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82?= =?UTF-8?q?=D0=B0=20=E2=84=961=20"=D0=9A=D0=BE=D0=BD=D1=81=D0=BE=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=B5=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/compiler.xml | 6 ++ .idea/gradle.xml | 18 ++++++ .idea/misc.xml | 10 ++++ .idea/vcs.xml | 6 ++ src/main/java/Calculate.java | 103 +++++++++++++++++++++++++++++++++++ src/main/java/Const.java | 5 ++ src/main/java/Main.java | 30 ++++++++-- 8 files changed, 177 insertions(+), 4 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 create mode 100644 src/main/java/Const.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..b9f2f6b --- /dev/null +++ b/src/main/java/Calculate.java @@ -0,0 +1,103 @@ + +import java.util.ArrayList; +import java.util.Scanner; + +public class Calculate { + static Const aConst=new Const(); + static Scanner scanner = new Scanner(System.in); + static ArrayList product = new ArrayList(); + static ArrayList price = new ArrayList(); + static double score = 0; + + public static void calculate() { + int count; + while (true){ + while (true)//проверка ввода целого числа + { + System.out.println("На сколько человек разделить заказ?"); + System.out.println("Введите целое больше 1"); + if (scanner.hasNextInt()) + { + count = Integer.parseInt(scanner.nextLine()); + System.out.println("Вы ввели: " + count); + break; + } + else + { + System.out.println("Вы ввели не целое число"); + scanner.nextLine(); + }} + if (count<=1) { + System.out.println("Оглянись! Ты тут один наел на 15 тысяч"); + } else { + //блок заполнения листа и подсчета счета + System.out.println(aConst.ADD_PRODUCT_AND_PRICE); + String nameProduct = scanner.next();//название продукта + Double priceProduct = scanner.nextDouble();//цена + addProduct(nameProduct); + addPrice(priceProduct); + System.out.println(aConst.ADD_MESSAGE_PRODUCT); + while (true) { + System.out.println(aConst.QUESTION_MESSAGE); + String question = scanner.next(); + if (question.equalsIgnoreCase("Да")) { + System.out.println(aConst.ADD_PRODUCT_AND_PRICE); + String addNameProduct = scanner.next(); + double addPriceProduct = scanner.nextDouble(); + addProduct(addNameProduct); + addPrice(addPriceProduct); + System.out.println(aConst.ADD_MESSAGE_PRODUCT); + } else if (question.equalsIgnoreCase("Завершить")) { + printProductAndPrice(); + score = score / count; + printResult(score); + break; + } + } + break; + } + } + + + } + + private static void addProduct(String addProduct) { + product.add(addProduct); + } + private static void addPrice(Double addPrice) { + price.add(addPrice); + } + + //ввывод товаров и стоимость каждого продукта + private static void printProductAndPrice() { + System.out.println("Добавленные товары:"); + for (double price : price) { + score = score + Math.abs(price); + } + for (int i=0;i= 11 && Math.floor(score1) % 100 <= 19) { + System.out.printf("Каждый должен заплатить: %.2f Рублей%n",score1); + } else { + switch ((int) (Math.floor(score1) % 10)) { + case 1: + System.out.printf("Каждый должен заплатить: %.2f Рубль%n",score1); + break; + case 2: + case 3: + case 4: + System.out.printf("Каждый должен заплатить: %.2f Рубля%n",score1); + break; + default: + System.out.printf("Каждый должен заплатить: %.2f Рублей%n",score1); + break; + } + } + } +} + diff --git a/src/main/java/Const.java b/src/main/java/Const.java new file mode 100644 index 0000000..2f23c9c --- /dev/null +++ b/src/main/java/Const.java @@ -0,0 +1,5 @@ +public class Const{ + final String ADD_MESSAGE_PRODUCT="Товар успешно добавлен"; + final String QUESTION_MESSAGE="Хотите ли вы добавить еще товар, выберите напишите 'Да' или напишите 'Завершить' для выхода"; + final String ADD_PRODUCT_AND_PRICE="Укажите название товара и его стоимость"; +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..e0be025 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,30 @@ +import java.util.Scanner; + public class Main { + static Calculate calculate=new Calculate(); public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + + calculate.calculate(); + /*Scanner in = new Scanner(System.in); + int ab; + while (true) + { + System.out.println("Введите число"); + if (in.hasNextInt()) + { + ab = Integer.parseInt(in.nextLine()); + System.out.println("Вы ввели: " + ab); + break; + } + else + { + System.out.println("Вы ввели не число"); + in.nextLine(); + }}*/ + } + } -} + + +

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