From 299d54be0c1550ab0fac5db480f4fd9fa10b262e Mon Sep 17 00:00:00 2001 From: Alkrasen Date: Fri, 25 Nov 2022 17:23:53 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 + .idea/codeStyles/Project.xml | 123 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/compiler.xml | 6 ++ .idea/gradle.xml | 18 ++++ .idea/misc.xml | 10 +++ .idea/vcs.xml | 6 ++ src/main/java/Calculator.java | 48 +++++++++++ src/main/java/Finish.java | 22 +++++ src/main/java/Main.java | 28 +++++- 10 files changed, 265 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml create mode 100644 src/main/java/Calculator.java create mode 100644 src/main/java/Finish.java 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/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..7643783 --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,123 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ 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/Calculator.java b/src/main/java/Calculator.java new file mode 100644 index 0000000..703206b --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,48 @@ +import java.util.Scanner; +public class Calculator { + public static void calc(int people){ + String dish; + String allDishes = ""; + float price; + float sumOfOrder = 0.0f; + String close; + while(true){ + System.out.println("Введите название блюда!"); + Scanner scSecond = new Scanner(System.in); + dish = scSecond.nextLine(); + allDishes = allDishes + dish + "\n"; + System.out.println("Введите стоимость этого блюда в формате 'руб.коп'"); + Scanner scThird = new Scanner(System.in); + if(scThird.hasNextFloat()){ + price = scThird.nextFloat(); + if(price > 0 ){ + sumOfOrder = sumOfOrder + price; + String sufForOne = Finish.finish(price); + System.out.println("Вы добавили " + dish + " за " + price + sufForOne ); + System.out.println("Хотите добавить блюдо? Введите любую букву или напишите:'Завершить', если блюд больше не осталось"); + Scanner scFourth = new Scanner(System.in); + close = scFourth.next(); + if (close.equalsIgnoreCase("Завершить")){ + break; + } + } + else{ + System.out.println("Сумма указана неверно"); + } + } + else{ + System.out.println("Сумма указана неверно, попробуйте внести блюдо снова"); + } + + } + String suf = Finish.finish(sumOfOrder); + float forThePerson = sumOfOrder / people; + String lastSuf = Finish.finish(forThePerson); + + System.out.println("Вы купили:\n" + allDishes + "За " + String.format("%.2f", sumOfOrder) + suf); + System.out.println("Каждый должен заплатить по: " + String.format("%.2f",forThePerson) + lastSuf); + + + + } +} diff --git a/src/main/java/Finish.java b/src/main/java/Finish.java new file mode 100644 index 0000000..2c8a170 --- /dev/null +++ b/src/main/java/Finish.java @@ -0,0 +1,22 @@ +public class Finish { + public static String finish(float overallCost) { + String suffix; + int hundred = (int) Math.floor(overallCost % 100); + if (hundred <= 20 && hundred >= 5) { + suffix = " рублей "; + } else { + int ten = hundred % 10; + if (ten == 1) { + suffix = " рубль "; + } else if (ten >= 2 && ten <= 4) { + suffix = " рубля "; + } else { + suffix = " рублей "; + } + + + } +return suffix; + } + } + diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..4dadcf4 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,28 @@ +import java.util.Scanner; + public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + + int howManyPeople; + while (true) { + System.out.println("На сколько человек необходимо разделить счет?"); + Scanner scFirst = new Scanner(System.in); + if(scFirst.hasNextInt()){ + howManyPeople = scFirst.nextInt(); + if(howManyPeople > 1){ + break; + } + if(howManyPeople <= 1) { + System.out.println("Извините, но необходимо ввести число гостей, которое больше 1!"); + } + } else { + System.out.println("Извините, но необходжмо ввести целочисленное значение больше 1"); + } + } + Calculator.calc(howManyPeople); + } + } -} + + From 6bed322d45d02d6a19effee189bea2998cd3ed75 Mon Sep 17 00:00:00 2001 From: Alkrasen Date: Sun, 27 Nov 2022 16:33:02 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA?= =?UTF-8?q?=D1=83=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 35 +++++++++++++++++------------------ src/main/java/Finish.java | 7 +++---- src/main/java/Main.java | 32 +++++++++++++++----------------- 3 files changed, 35 insertions(+), 39 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 703206b..12e0087 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -1,36 +1,36 @@ import java.util.Scanner; + public class Calculator { - public static void calc(int people){ + static String exit = "Завершить"; // Вынес в статическую константу "Завершить" + + public static void calc(int people) { String dish; String allDishes = ""; float price; float sumOfOrder = 0.0f; String close; - while(true){ + while (true) { + Scanner scSecond = new Scanner(System.in); // Оставил один сканнер System.out.println("Введите название блюда!"); - Scanner scSecond = new Scanner(System.in); dish = scSecond.nextLine(); - allDishes = allDishes + dish + "\n"; System.out.println("Введите стоимость этого блюда в формате 'руб.коп'"); - Scanner scThird = new Scanner(System.in); - if(scThird.hasNextFloat()){ - price = scThird.nextFloat(); - if(price > 0 ){ + if (scSecond.hasNextFloat()) { + price = scSecond.nextFloat(); + if (price > 0) { sumOfOrder = sumOfOrder + price; + allDishes = allDishes + dish + "\n"; String sufForOne = Finish.finish(price); - System.out.println("Вы добавили " + dish + " за " + price + sufForOne ); + String anotherOne = "Вы добавили: %s за %.2f%s\n"; + System.out.printf(anotherOne, dish, price, sufForOne); System.out.println("Хотите добавить блюдо? Введите любую букву или напишите:'Завершить', если блюд больше не осталось"); - Scanner scFourth = new Scanner(System.in); - close = scFourth.next(); - if (close.equalsIgnoreCase("Завершить")){ + close = scSecond.next(); + if (close.equalsIgnoreCase(exit)) { break; } - } - else{ + } else { System.out.println("Сумма указана неверно"); } - } - else{ + } else { System.out.println("Сумма указана неверно, попробуйте внести блюдо снова"); } @@ -40,8 +40,7 @@ public static void calc(int people){ String lastSuf = Finish.finish(forThePerson); System.out.println("Вы купили:\n" + allDishes + "За " + String.format("%.2f", sumOfOrder) + suf); - System.out.println("Каждый должен заплатить по: " + String.format("%.2f",forThePerson) + lastSuf); - + System.out.println("Каждый должен заплатить по: " + String.format("%.2f", forThePerson) + lastSuf); } diff --git a/src/main/java/Finish.java b/src/main/java/Finish.java index 2c8a170..a3b5989 100644 --- a/src/main/java/Finish.java +++ b/src/main/java/Finish.java @@ -2,7 +2,7 @@ public class Finish { public static String finish(float overallCost) { String suffix; int hundred = (int) Math.floor(overallCost % 100); - if (hundred <= 20 && hundred >= 5) { + if (hundred <= 14 && hundred >= 11) { // Исправил suffix = " рублей "; } else { int ten = hundred % 10; @@ -14,9 +14,8 @@ public static String finish(float overallCost) { suffix = " рублей "; } - } -return suffix; - } + return suffix; } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 4dadcf4..c918f2a 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,25 +4,23 @@ public class Main { public static void main(String[] args) { - int howManyPeople; - while (true) { - System.out.println("На сколько человек необходимо разделить счет?"); - Scanner scFirst = new Scanner(System.in); - if(scFirst.hasNextInt()){ - howManyPeople = scFirst.nextInt(); - if(howManyPeople > 1){ - break; - } - if(howManyPeople <= 1) { - System.out.println("Извините, но необходимо ввести число гостей, которое больше 1!"); - } - } else { - System.out.println("Извините, но необходжмо ввести целочисленное значение больше 1"); - } + int howManyPeople; + while (true) { + System.out.println("На сколько человек необходимо разделить счет?"); + Scanner scFirst = new Scanner(System.in); + if (scFirst.hasNextInt()) { + howManyPeople = scFirst.nextInt(); + if (howManyPeople > 1) { + break; } - Calculator.calc(howManyPeople); + System.out.println("Извините, но необходимо ввести число гостей, которое больше 1!");// Убрал один if, который был, как оказалось, не нужен + } else { + System.out.println("Извините, но необходжмо ввести целочисленное значение больше 1"); } - + } + Calculator.calc(howManyPeople); } +} +