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 によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル