diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java new file mode 100644 index 0000000..cf10fae --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,27 @@ +public class Calculator { + String foodName; + String totalFoodList = ""; + int persons; + double foodCost; + double totalCost; + double costPerPerson; + + + double foodCostCalc (int persons, double foodCost) { + this.persons = persons; + this.foodCost = foodCost; + totalCost += this.foodCost; + System.out.println("Блюдо успешно добавлено в общий счет"); + return totalCost; + + + } + String foodNameConcat (String foodName) { + this.foodName = foodName; + totalFoodList += this.foodName + "\n"; + return totalFoodList; + + } + + +} diff --git a/src/main/java/Check.java b/src/main/java/Check.java new file mode 100644 index 0000000..395fb7a --- /dev/null +++ b/src/main/java/Check.java @@ -0,0 +1,20 @@ +import java.util.Scanner; + +public class Check { + + String currencyAddition(double num){ + double adds = num % 100; + int addsInvert = (int) (Math.floor(adds)); + + switch (addsInvert){ + case 1: + return "рубль"; + case 2: + case 3: + case 4: + return "рубля"; + default: + return "рублей"; + } + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..728d337 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,61 @@ +import java.util.Scanner; public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + int persons; + String foodName; + double foodCost; + String totalFoodList; + double totalCost; + String statement; + + + while (true) { + System.out.println("Введите количество участников"); + Scanner input = new Scanner(System.in); + if (input.hasNextInt()) { + persons = input.nextInt(); + if (persons <= 0) {System.out.println("Количество участников отрицательно или равно нулю. Попробуйте еще раз.");} + else if (persons == 1) {System.out.println("Нет необходимости делить счет");} + else if (persons>0) {break;} + } + + else {System.out.println("Вы ввели неверные данные. Попробуйте еще раз.");} + + } + + Calculator calculating = new Calculator(); + + + while (true) { + Scanner dishesInput = new Scanner (System.in); + System.out.println("Что Вы с друзями заказали ?"); + + foodName = dishesInput.next(); + totalFoodList = calculating.foodNameConcat(foodName); + System.out.println("Сколько стоило это блюдо ?"); + + + if (dishesInput.hasNextDouble()) { + foodCost = dishesInput.nextDouble(); + totalCost = calculating.foodCostCalc(persons,foodCost); + System.out.println("Это все ? Завершить/Нет"); + statement = dishesInput.next(); + if (statement.equalsIgnoreCase("Завершить")) { + break; + } + } + + else {System.out.println("Что-то не так со стоимостью блюда. Попробуйте еще раз.");} + + } + + + Check cur = new Check(); + + System.out.println("Ваш заказ: " + "\n" + totalFoodList); + System.out.println("Ваш общий счет: " + String.format("%,.2f", totalCost) + " " + cur.currencyAddition(totalCost) ); + System.out.println("Каждый должен оплатить " + String.format("%,.2f", (totalCost/persons)) + " " + cur.currencyAddition(totalCost/persons)); + } }

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