From 6c71eceaa5ec5bc2a000713fdde18d5cee69b04e Mon Sep 17 00:00:00 2001 From: Sergun8 Date: 2022年11月26日 01:26:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BF=D1=80=D0=B8=D0=BD=D1=82=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 ++ .idea/.name | 1 + .idea/compiler.xml | 6 +++ .idea/gradle.xml | 18 +++++++ .idea/misc.xml | 10 ++++ .idea/vcs.xml | 6 +++ src/main/java/Main.java | 101 +++++++++++++++++++++++++++++++++++++++- 7 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/.name 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/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/Main.java b/src/main/java/Main.java index a9198c4..8daec5f 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,107 @@ +import java.util.Scanner; + public class Main { public static void main(String[] args) { // ваш код начнется здесь // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + Scanner scanner = new Scanner(System.in); + + int pipl = 0; //Количество человек + String pruduct = ""; // Наименование товара + double price = 0; // Цена товара + + do { + System.out.println("На скольких человек необходимо разделить счет?"); + if (scanner.hasNextInt()) { + pipl = scanner.nextInt(); + switch ((pipl> 1) ? 0 : (pipl == 1) ? 1 : 2 ) { + case 0: + System.out.println("Счет будет разделен на " + pipl + " человек"); + break; + case 1: + System.out.println("За все платите Вы. Значение должно быть больше единицы, попробуйте ещё раз."); + break; + case 2: + System.out.println("Ошибка. Это некорректное значение для подсчёта. Попробуйте ещё раз."); + } + } + else { + System.out.println("Значение некорректно, оно должно быть больше единицы. Попробуйте ещё раз."); + scanner.next(); + } + } while (pipl<=1); + + class Calculator { + int pipl; + double price; + double sumPrice; + double totalSum; + String list = "Добавленные товары:"; + String product = ""; + + Calculator(int pipl, String pruduct, double price) { + this.pipl = pipl; + this.product = pruduct; + this.price = price; + } + void addInput(String product, double price) { + sumPrice += price; + list = list + "\n" + product; + System.out.println(product + " в списке товаров"); + totalSum = (double) sumPrice/pipl; + } + } + + class Format { + String textRub (double price) { + double formatRub = Math.floor(price)%10; + if (formatRub == 1) { + return "рубль"; + } + else + if (formatRub>= 2 && formatRub <= 4) { + return "рубля"; + } + else { + return "рублей"; + } + } + String Rub(final double result) { + return String.format("%.2f", result); + } + } + + Calculator calc = new Calculator(pipl, pruduct, price); + + while (true) { + System.out.println("Введите название товара"); + String product = scanner.next(); + while (true) { + System.out.println("Введите стоимость товара в формате: 'рубли.копейки' [10,45; 11,40]"); + if (scanner.hasNextDouble()) { + price = scanner.nextDouble(); + break; + } + else { + System.out.println("Значение некорректно. Попробуйте ещё раз."); + scanner.next(); + } + } + + calc.addInput(product, price); + + System.out.println("Хотите добавить еще один товар? \nВведите 'Y' для продолжения, либо 'N' для завершения"); + String question = scanner.next(); + if (question.equalsIgnoreCase("N")||question.equalsIgnoreCase("Т")||question.equalsIgnoreCase("Завершить")) { + break; + } + } + + Format format = new Format(); + + System.out.println(calc.list); + System.out.println("С каждого по: " + format.Rub(calc.totalSum) + " " + format.textRub(calc.totalSum)); + //System.out.println("Привет Мир"); } }

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