From e6fb7daceadc7370de98eb7fa7a7a3c5e7552c3c Mon Sep 17 00:00:00 2001 From: s-buvaka Date: Wed, 30 Nov 2022 22:20:36 +0300 Subject: [PATCH 1/2] Add dev branch --- src/main/java/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c435..955424e69 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,3 +1,4 @@ +// dev branch for Y.Practicum public class Main { public static void main(String[] args) { From 1487450e1c44d718f0b9ee0d74d7afee2d374df3 Mon Sep 17 00:00:00 2001 From: DeveloperTagir Date: Tue, 31 Jan 2023 12:38:50 +0600 Subject: [PATCH 2/2] =?UTF-8?q?=D0=BF=D1=80=D0=BE=D0=B5=D0=BA=D1=82=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=E2=84=96?= =?UTF-8?q?1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 100 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 955424e69..76f39f87c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,105 @@ +import java.util.Random; +import java.util.Scanner; + // dev branch for Y.Practicum public class Main { + static CountPersons countPersons = new CountPersons(); + static int persons = 0; + static double sum = 0; public static void main(String[] args) { // ваш код начнется здесь // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + + countPersons.quantityOfPersons(); + addProduct(); + finish(); + + } + public static class CountPersons { + + + void quantityOfPersons() { + Scanner scanner = new Scanner(System.in); + System.out.println("Сколько вас человек?"); + while (true) { + if (scanner.hasNextInt()) { + persons = scanner.nextInt(); + + + + if (persons == 1) { + System.out.println("Вы один, нет смысла делить."); + } else if (persons < 1) { + System.out.println("Неверное значение меньше 1"); + } else if (persons > 1) { + break; + } else { + System.out.println("Вы ввели не число"); + scanner.nextLine(); + } + } + } + } + } + public static void addProduct() { + Scanner scanner = new Scanner(System.in); + + double price = 0; + String productList = "Добавленные товары: \n"; + String product = null; + + System.out.println("напишите блюдо"); + + while ((product = scanner.nextLine()) != null) { + if (product.equalsIgnoreCase("Завершить")) { + System.out.println(productList); + String str2 = String.format("Общая сумма товаров составила: %.2f", sum); + System.out.println(str2); + break; + } + System.out.println("сколько стоит блюдо?"); + while (true) { + if (scanner.hasNextDouble()) { + price = scanner.nextDouble(); + if (price < 0) { + System.out.println("Введённая сумма меньше 0"); + } else if (price >= 0) { + sum += price; + productList += product + "\n"; + String str = String.format("%s стоимостью %.2f добавлено. Сумма: %.2f", product, price, sum); + System.out.println(str); + System.out.println("напишите блюдо"); + break; + } else { + System.out.println("Введено не число"); + scanner.nextLine(); + } + } + } + scanner.nextLine(); + } + } + + public static void finish() { + double total = sum/persons; + int num1 = (int) (total); + String result = null; + if (total % 100 > 4 && total % 100 < 21) { + result = "рублей"; + } else if (total % 10 == 1) { + result = "рубль"; + } else if (total % 10 > 1 && total % 10 < 5) { + result = "рубля"; + } + int num2 = persons; + String result2 = null; + if (num2 % 100 > 4 && num2 % 100 < 21) { + result2 = "человека"; + } else if (num2 % 10 > 1 && num2 % 10 < 5) { + result2 = "человек"; + String str = String.format("Вас %d %s, С каждого по %.2f %s", persons, result2, total, result); + System.out.println(str); + } } -} +} \ No newline at end of file