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/Calculate.java b/src/main/java/Calculate.java new file mode 100644 index 0000000..33e944c --- /dev/null +++ b/src/main/java/Calculate.java @@ -0,0 +1,73 @@ +import java.util.Scanner; +public class Calculate { + int guest; + String totalName = ""; + double totalPrice = 0.00f; + String rub = ""; + Scanner scanner = new Scanner(System.in); + + + public void addGuests() { + while (true) { + System.out.println("Введите количество человек в вашей компании:"); + if (scanner.hasNextInt()) { + guest = scanner.nextInt(); + if (guest > 1) { + System.out.println("Спасибо! Разделим счёт на " + guest + " человек(а)\nПриступим к заполнению заказа."); + break;// + } else { + System.out.println("Некорректное значение гостей, попробуйте снова!"); + } + } else { + System.out.println("Ожидается ввод числового значения, попробуйте снова!"); + scanner.nextLine(); + } + } + } + public void sumProducts() { + while (true) { + System.out.println("Введите название товара:\nЧтобы закончить ввод, введите 'Завершить'"); + String name = scanner.next(); + String cancel = "Завершить"; + boolean check = cancel.equalsIgnoreCase(name); + if (check) { + System.out.println("Ваш заказ: " + "\n" + totalName); + System.out.println("На общую стоимость: " + totalPrice + " руб."); + break; + } else { + totalName = totalName + name + "\n"; + System.out.println("Введите стоимость товара (рубли,копейки):"); + while (true) { + if (scanner.hasNextDouble()) { + double price = scanner.nextDouble(); + if (price > 0) { + totalPrice = totalPrice + price; + System.out.println("Спасибо! Ваш товар добавлен в заказ!"); + break; + } else { + System.out.println("Некорректное значение цены, попробуйте снова!"); + } + } else { + System.out.println("Ожидается ввод числового значения, попробуйте снова!"); + scanner.next(); + } + } + } + } + } + + public void divTotalPrice() { + double guestSum = totalPrice / (double)guest; + int lastNum = (int) guestSum % 10; + if (totalPrice % 100 >= 11 && totalPrice % 100 <= 20) { + rub = "рублей"; + } else if (lastNum > 1 && lastNum < 5) { + rub = "рубля"; + } else if (lastNum % 10 == 1) { + rub = "рубль"; + } else { + rub = "рублей"; + } + System.out.println("Сумма заказа на каждого гостя составила " + String.format("%.2f", guestSum) + " " + rub + ".\nЖдём Вас у нас снова!"); + } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..1e9a4a1 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,9 @@ public class Main { - public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + Calculate calculate = new Calculate(); + calculate.addGuests(); + calculate.sumProducts(); + calculate.divTotalPrice(); + } -} +} \ No newline at end of file