From 5559530037ced8eacca0aa4bf5c7b5eb69bc3a87 Mon Sep 17 00:00:00 2001 From: psycow Date: Tue, 25 Oct 2022 19:43:38 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=20=D0=BE=D0=B4=D0=B8=D0=BD.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 +++ .idea/compiler.xml | 6 ++++++ .idea/gradle.xml | 18 ++++++++++++++++++ .idea/misc.xml | 10 ++++++++++ .idea/vcs.xml | 6 ++++++ src/main/java/Main.java | 25 ++++++++++++++++++++++--- 6 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/gradle.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/vcs.xml 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/Main.java b/src/main/java/Main.java index a9198c4..c86c58f 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,27 @@ +import java.util.Scanner; + public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + numberOfGuestsQuestion(); + } + private static int numberOfGuestsQuestion(){ + int guestAmount = 0; + Scanner scanner = new Scanner(System.in); + int userInput = 0; + while (true){ + System.out.println("Введите количество гостей."); + userInput = scanner.nextInt(); + if (userInput == 1){ + System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт."); + }else if (userInput <2) { + System.out.println("Количество гостей не может быть меньше 1. Введите корректное значение."); + }else { + guestAmount = userInput; + System.out.println("Количество гостей: " + guestAmount); + return guestAmount; + } + + } } } From 37d12f7f42cf5f680ec0fd0883527bc3c415bfe1 Mon Sep 17 00:00:00 2001 From: psycow Date: Tue, 25 Oct 2022 19:57:33 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=20=D0=B4=D0=B2=D0=B0.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index c86c58f..6a82995 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -3,10 +3,10 @@ public class Main { public static void main(String[] args) { - numberOfGuestsQuestion(); + int guestAmount = numberOfGuestsQuestion(); + System.out.println("Количество гостей: " + guestAmount); } private static int numberOfGuestsQuestion(){ - int guestAmount = 0; Scanner scanner = new Scanner(System.in); int userInput = 0; while (true){ @@ -15,11 +15,9 @@ private static int numberOfGuestsQuestion(){ if (userInput == 1){ System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт."); }else if (userInput <2) { - System.out.println("Количество гостей не может быть меньше 1. Введите корректное значение."); + System.out.println("Количество гостей не может быть меньше 1. В этом случае нет смысла ничего считать и делить."); }else { - guestAmount = userInput; - System.out.println("Количество гостей: " + guestAmount); - return guestAmount; + return userInput; } } From ccbe25677465f41b55e8ae7151d015453229bba6 Mon Sep 17 00:00:00 2001 From: psycow Date: Tue, 25 Oct 2022 22:39:32 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=203.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 7 +++++++ src/main/java/Calculator.java | 28 ++++++++++++++++++++++++++++ src/main/java/Main.java | 10 +++++++--- 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/main/java/Calculator.java diff --git a/build.gradle b/build.gradle index 1b1d075..ce37dd3 100644 --- a/build.gradle +++ b/build.gradle @@ -8,3 +8,10 @@ repositories { dependencies { } + +if (hasProperty('buildScan')) { + buildScan { + termsOfServiceUrl = 'https://gradle.com/terms-of-service' + termsOfServiceAgree = 'yes' + } +} \ 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..8681a5c --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,28 @@ +import java.util.Scanner; + +public class Calculator { + + + static Scanner scanner = new Scanner(System.in); + String userInput; + static String productName; + static String allProductsList; + static float productCost = 0.0F; + static float allProductsCost = 0.0F; + + public static void addingProducts() { + String userInput = null; + while (userInput.toUpperCase() != "ЗАВЕРШИТЬ"){ + System.out.println("Введите название товара и его стоимость.\nТовар: "); + productName = scanner.next(); + allProductsList = allProductsList + " " + productName; + System.out.println("Введите стоимость: "); + productCost = scanner.nextFloat(); + allProductsCost = allProductsCost + productCost; + + System.out.println("Вы успешно добавили" + productName + "за" + productCost + "рублей.\nХотите добавить ещё один товар?"); + userInput = scanner.next(); + } + } + } + diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 6a82995..9391e1a 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,10 +1,14 @@ import java.util.Scanner; + public class Main { public static void main(String[] args) { - int guestAmount = numberOfGuestsQuestion(); - System.out.println("Количество гостей: " + guestAmount); + + //int guestAmount = numberOfGuestsQuestion(); + //System.out.println("Количество гостей: " + guestAmount); + Calculator calculator = new Calculator(); + calculator.addingProducts(); } private static int numberOfGuestsQuestion(){ Scanner scanner = new Scanner(System.in); @@ -15,7 +19,7 @@ private static int numberOfGuestsQuestion(){ if (userInput == 1){ System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт."); }else if (userInput <2) { - System.out.println("Количество гостей не может быть меньше 1. В этом случае нет смысла ничего считать и делить."); + System.out.println("Количество гостей не может быть меньше 1. Оглядитесь в поисках своих друзей."); }else { return userInput; } From 4f90a7b036f919d90e810d23e5133dc4a13736b5 Mon Sep 17 00:00:00 2001 From: harhanov Date: Fri, 28 Oct 2022 16:37:37 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D0=9F=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D1=8F?= =?UTF-8?q?=D0=B5=D1=82=20=D0=BA=D0=BE=D0=BB=D0=B8=D1=87=D0=B5=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=BE=20=D0=B3=D0=BE=D1=81=D1=82=D0=B5=D0=B9,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=20=D0=B2=20?= =?UTF-8?q?=D1=81=D0=BF=D0=B8=D1=81=D0=BE=D0=BA=20=D0=BF=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D1=8B=20=D0=B8=20=D0=B2=D1=8B=D0=B2=D0=BE?= =?UTF-8?q?=D0=B4=D0=B8=D1=82=20=D0=B5=D0=B3=D0=BE.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/codeStyles/Project.xml | 123 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ src/main/java/Calculator.java | 49 ++++++++--- src/main/java/Divider.java | 2 + src/main/java/Main.java | 23 +++-- 5 files changed, 179 insertions(+), 23 deletions(-) create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml create mode 100644 src/main/java/Divider.java 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/src/main/java/Calculator.java b/src/main/java/Calculator.java index 8681a5c..5f19693 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -2,27 +2,54 @@ public class Calculator { - static Scanner scanner = new Scanner(System.in); - String userInput; + static String userInput = null; static String productName; - static String allProductsList; + static String allProductsList = "Добавленные товары:"; static float productCost = 0.0F; static float allProductsCost = 0.0F; + static String checkedNumber = null; - public static void addingProducts() { - String userInput = null; - while (userInput.toUpperCase() != "ЗАВЕРШИТЬ"){ + static void printResult(int numberOfGuests) { + while (!"ЗАВЕРШИТЬ".equalsIgnoreCase(userInput)){ System.out.println("Введите название товара и его стоимость.\nТовар: "); productName = scanner.next(); - allProductsList = allProductsList + " " + productName; + allProductsList = allProductsList + "\n" + productName; System.out.println("Введите стоимость: "); - productCost = scanner.nextFloat(); - allProductsCost = allProductsCost + productCost; + checkedNumber = scanner.next(); + + while (true){ + if (!isItaNumber(checkedNumber)){ + System.out.println("Бип, ошибка. Это не число, либо вы в качестве делителя используете запятую вместо точки.\nПопробуйте ещё раз. Введите стоимость: "); + checkedNumber = scanner.next(); + }else if (!isItPositive(productCost = Float.parseFloat(checkedNumber))){ + System.out.println("Бип, ошибка. Стоимость не может быть отрицательной!\nПопробуйте ещё раз. Введите стоимость: "); + checkedNumber = scanner.next(); + }else{ + + break; + } + } - System.out.println("Вы успешно добавили" + productName + "за" + productCost + "рублей.\nХотите добавить ещё один товар?"); + allProductsCost += productCost; + System.out.println("Вы успешно добавили " + productName + " за " + productCost + " рублей.\nЕсли хотите завершить, наберите \"Завершить\" и нажмите \"enter\".\nЕсли хотите добавить ещё один товар, введите любой символ или слово и нажмите \"enter\"."); userInput = scanner.next(); } + System.out.println(allProductsList + "\nОбщая сумма: " + allProductsCost+ " рублей."); + + } + + private static boolean isItPositive(float productCost) { + if (productCost>=0) { + return true; + }else{ + return false; + } + } + + private static boolean isItaNumber(String checkedNumber) { + + return checkedNumber.matches("-?\\d+(\\.\\d+)?"); } - } +} diff --git a/src/main/java/Divider.java b/src/main/java/Divider.java new file mode 100644 index 0000000..138032c --- /dev/null +++ b/src/main/java/Divider.java @@ -0,0 +1,2 @@ +public class Divider { +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 9391e1a..c08834c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,27 +1,26 @@ import java.util.Scanner; - public class Main { public static void main(String[] args) { + int numberOfGuests = 0; + numberOfGuestsQuestion(); + Calculator.printResult(numberOfGuests); - //int guestAmount = numberOfGuestsQuestion(); - //System.out.println("Количество гостей: " + guestAmount); - Calculator calculator = new Calculator(); - calculator.addingProducts(); + //Calculator calculator = new Calculator(); } - private static int numberOfGuestsQuestion(){ + static int numberOfGuestsQuestion(){ Scanner scanner = new Scanner(System.in); - int userInput = 0; + int numberOfGuests = 0; while (true){ System.out.println("Введите количество гостей."); - userInput = scanner.nextInt(); - if (userInput == 1){ + numberOfGuests = scanner.nextInt(); + if (numberOfGuests == 1){ System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт."); - }else if (userInput <2) { - System.out.println("Количество гостей не может быть меньше 1. Оглядитесь в поисках своих друзей."); + }else if (numberOfGuests <2) { + System.out.println("Количество гостей не может быть меньше 1. Вероятно вы ошиблись."); }else { - return userInput; + return numberOfGuests; } } From c217e65da7d9d6c7ded074c2088f04a04a90f88b Mon Sep 17 00:00:00 2001 From: psycow Date: Sat, 29 Oct 2022 12:26:29 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=201.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 43 +++++++++++++++++++++++++---------- src/main/java/Main.java | 16 ++++++------- 2 files changed, 38 insertions(+), 21 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 5f19693..9a16014 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -8,11 +8,12 @@ public class Calculator { static String allProductsList = "Добавленные товары:"; static float productCost = 0.0F; static float allProductsCost = 0.0F; + static float personalAmount = 0.0F; static String checkedNumber = null; static void printResult(int numberOfGuests) { while (!"ЗАВЕРШИТЬ".equalsIgnoreCase(userInput)){ - System.out.println("Введите название товара и его стоимость.\nТовар: "); + System.out.println("Введите название товара и его цену.\nТовар: "); productName = scanner.next(); allProductsList = allProductsList + "\n" + productName; System.out.println("Введите стоимость: "); @@ -20,10 +21,10 @@ static void printResult(int numberOfGuests) { while (true){ if (!isItaNumber(checkedNumber)){ - System.out.println("Бип, ошибка. Это не число, либо вы в качестве делителя используете запятую вместо точки.\nПопробуйте ещё раз. Введите стоимость: "); + System.out.println("Бип, ошибка. Это не число, либо вы в качестве делителя используете запятую вместо точки.\nПопробуйте ещё раз. Введите цену: "); checkedNumber = scanner.next(); }else if (!isItPositive(productCost = Float.parseFloat(checkedNumber))){ - System.out.println("Бип, ошибка. Стоимость не может быть отрицательной!\nПопробуйте ещё раз. Введите стоимость: "); + System.out.println("Бип, ошибка. Цена не может быть отрицательной!\nПопробуйте ещё раз. Введите цену: "); checkedNumber = scanner.next(); }else{ @@ -32,24 +33,42 @@ static void printResult(int numberOfGuests) { } allProductsCost += productCost; - System.out.println("Вы успешно добавили " + productName + " за " + productCost + " рублей.\nЕсли хотите завершить, наберите \"Завершить\" и нажмите \"enter\".\nЕсли хотите добавить ещё один товар, введите любой символ или слово и нажмите \"enter\"."); + System.out.println("Вы успешно добавили " + productName + " за " + String.format("%.2f", productCost) + " рублей.\nЕсли хотите завершить, наберите \"Завершить\" и нажмите \"enter\".\nЕсли хотите добавить ещё один товар, введите любой символ или слово и нажмите \"enter\"."); userInput = scanner.next(); } - System.out.println(allProductsList + "\nОбщая сумма: " + allProductsCost+ " рублей."); + String rubleEnding = getRubleEnding((int) Math.floor(allProductsCost)); + System.out.println(allProductsList + "\nОбщая сумма: " + String.format("%.2f",allProductsCost) + rubleEnding); + personalAmount = allProductsCost / numberOfGuests; + String personalRubleEnding = getRubleEnding((int) Math.floor(personalAmount)); + System.out.println("Каждому гостю необходимо заплатить: " + String.format("%.2f", personalAmount) + personalRubleEnding); } - private static boolean isItPositive(float productCost) { - if (productCost>=0) { - return true; - }else{ - return false; - } + + private static boolean isItPositive(float productCost) {// проверяем не является ли число отрицательным + return productCost >= 0; } - private static boolean isItaNumber(String checkedNumber) { + private static boolean isItaNumber(String checkedNumber) {// проверяем число ли ввёл пользователь return checkedNumber.matches("-?\\d+(\\.\\d+)?"); } + public static String getRubleEnding(int wholeRubles) { + int preLastDigit = wholeRubles % 100 / 10; + if (preLastDigit == 1) { + return " рублей."; + } else { + switch (wholeRubles % 10) { + case 1: + return " рубль."; + case 2: + case 3: + case 4: + return " рубля."; + default: + return " рублей."; + } + } +} } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index c08834c..e4b00e1 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -3,24 +3,22 @@ public class Main { public static void main(String[] args) { - int numberOfGuests = 0; - numberOfGuestsQuestion(); + + int numberOfGuests = getNumberOfGuests(); Calculator.printResult(numberOfGuests); - //Calculator calculator = new Calculator(); } - static int numberOfGuestsQuestion(){ + static int getNumberOfGuests(){ Scanner scanner = new Scanner(System.in); - int numberOfGuests = 0; while (true){ System.out.println("Введите количество гостей."); - numberOfGuests = scanner.nextInt(); - if (numberOfGuests == 1){ + int number = scanner.nextInt(); + if (number == 1){ System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт."); - }else if (numberOfGuests <2) { + }else if (number <2) { System.out.println("Количество гостей не может быть меньше 1. Вероятно вы ошиблись."); }else { - return numberOfGuests; + return number; } } From 57deb096b6097d750e2bf05fe5a3632600520bdc Mon Sep 17 00:00:00 2001 From: psycow Date: Sat, 29 Oct 2022 12:55:42 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D0=92=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20?= =?UTF-8?q?=D0=BD=D0=BE=D0=BC=D0=B5=D1=80=201.01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 87 ++++++++++++++++++----------------- src/main/java/Divider.java | 2 - src/main/java/Main.java | 23 ++++----- 3 files changed, 56 insertions(+), 56 deletions(-) delete mode 100644 src/main/java/Divider.java diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 9a16014..a848d28 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -2,58 +2,59 @@ public class Calculator { - static Scanner scanner = new Scanner(System.in); - static String userInput = null; - static String productName; - static String allProductsList = "Добавленные товары:"; - static float productCost = 0.0F; - static float allProductsCost = 0.0F; - static float personalAmount = 0.0F; - static String checkedNumber = null; + static Scanner scanner = new Scanner(System.in); + static String userInput = null; + static String productName; + static String allProductsList = "Добавленные товары:"; + static float productCost = 0.0F; + static float allProductsCost = 0.0F; + static float personalAmount = 0.0F; + static String checkedNumber = null; - static void printResult(int numberOfGuests) { - while (!"ЗАВЕРШИТЬ".equalsIgnoreCase(userInput)){ - System.out.println("Введите название товара и его цену.\nТовар: "); - productName = scanner.next(); - allProductsList = allProductsList + "\n" + productName; - System.out.println("Введите стоимость: "); - checkedNumber = scanner.next(); + static void printResult(int numberOfGuests) { + while (!"ЗАВЕРШИТЬ".equalsIgnoreCase(userInput)) {// цикл продолжается до ввода слова "заврешить" игнорируя регистр букв + System.out.println("Введите название товара и его цену.\nТовар: "); + productName = scanner.next(); + allProductsList = allProductsList + "\n" + productName; + System.out.println("Введите стоимость: "); + checkedNumber = scanner.next(); - while (true){ - if (!isItaNumber(checkedNumber)){ - System.out.println("Бип, ошибка. Это не число, либо вы в качестве делителя используете запятую вместо точки.\nПопробуйте ещё раз. Введите цену: "); - checkedNumber = scanner.next(); - }else if (!isItPositive(productCost = Float.parseFloat(checkedNumber))){ - System.out.println("Бип, ошибка. Цена не может быть отрицательной!\nПопробуйте ещё раз. Введите цену: "); - checkedNumber = scanner.next(); - }else{ + while (true) {// цикл проверяет число ли ввёл пользователь и не является ли оно отрицательным + if (!isItaNumber(checkedNumber)) { + System.out.println("Бип, ошибка. Это не число, либо вы в качестве делителя используете запятую вместо точки.\nПопробуйте ещё раз. Введите цену: "); + checkedNumber = scanner.next(); + } else if (!isItPositive(productCost = Float.parseFloat(checkedNumber))) { + System.out.println("Бип, ошибка. Цена не может быть отрицательной!\nПопробуйте ещё раз. Введите цену: "); + checkedNumber = scanner.next(); + } else { - break; - } + break; } - - allProductsCost += productCost; - System.out.println("Вы успешно добавили " + productName + " за " + String.format("%.2f", productCost) + " рублей.\nЕсли хотите завершить, наберите \"Завершить\" и нажмите \"enter\".\nЕсли хотите добавить ещё один товар, введите любой символ или слово и нажмите \"enter\"."); - userInput = scanner.next(); } - String rubleEnding = getRubleEnding((int) Math.floor(allProductsCost)); - System.out.println(allProductsList + "\nОбщая сумма: " + String.format("%.2f",allProductsCost) + rubleEnding); - personalAmount = allProductsCost / numberOfGuests; - String personalRubleEnding = getRubleEnding((int) Math.floor(personalAmount)); - System.out.println("Каждому гостю необходимо заплатить: " + String.format("%.2f", personalAmount) + personalRubleEnding); + allProductsCost += productCost; + System.out.println("Вы успешно добавили " + productName + " за " + String.format("%.2f", productCost) + " рублей.\nЕсли хотите завершить, наберите \"Завершить\" и нажмите \"enter\".\nЕсли хотите добавить ещё один товар, введите любой символ или слово и нажмите \"enter\"."); + userInput = scanner.next(); } + String rubleEnding = getRubleEnding((int) Math.floor(allProductsCost)); // выясняем верное окончание слова "рубль" для общей суммы заказа + System.out.println(allProductsList + "\nОбщая сумма: " + String.format("%.2f", allProductsCost) + rubleEnding); + personalAmount = allProductsCost / numberOfGuests; + String personalRubleEnding = getRubleEnding((int) Math.floor(personalAmount));// выясняем верное окончание слова "рубль" для суммы отдельного гостя + System.out.println("Каждому гостю необходимо заплатить: " + String.format("%.2f", personalAmount) + personalRubleEnding); + } - private static boolean isItPositive(float productCost) {// проверяем не является ли число отрицательным - return productCost >= 0; - } - private static boolean isItaNumber(String checkedNumber) {// проверяем число ли ввёл пользователь + private static boolean isItPositive(float productCost) {// проверяем не является ли число отрицательным + return productCost >= 0; + } - return checkedNumber.matches("-?\\d+(\\.\\d+)?"); - } - public static String getRubleEnding(int wholeRubles) { + private static boolean isItaNumber(String checkedNumber) {// проверяем число ли ввёл пользователь + + return checkedNumber.matches("-?\\d+(\\.\\d+)?"); + } + + public static String getRubleEnding(int wholeRubles) {// подбираем правльное окончание слову "рубль" int preLastDigit = wholeRubles % 100 / 10; if (preLastDigit == 1) { return " рублей."; @@ -67,8 +68,8 @@ public static String getRubleEnding(int wholeRubles) { case 4: return " рубля."; default: - return " рублей."; + return " рублей."; } + } } } -} diff --git a/src/main/java/Divider.java b/src/main/java/Divider.java deleted file mode 100644 index 138032c..0000000 --- a/src/main/java/Divider.java +++ /dev/null @@ -1,2 +0,0 @@ -public class Divider { -} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index e4b00e1..b06ecbe 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -8,18 +8,19 @@ public static void main(String[] args) { Calculator.printResult(numberOfGuests); } - static int getNumberOfGuests(){ + + static int getNumberOfGuests() { Scanner scanner = new Scanner(System.in); - while (true){ - System.out.println("Введите количество гостей."); - int number = scanner.nextInt(); - if (number == 1){ - System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт."); - }else if (number <2) { - System.out.println("Количество гостей не может быть меньше 1. Вероятно вы ошиблись."); - }else { - return number; - } + while (true) { + System.out.println("Введите количество гостей."); + int number = scanner.nextInt(); + if (number == 1) { + System.out.println("Количество гостей дожно быть не менее 2-х человек. Найдите кого-нибудь, с кем можно разделить счёт."); + } else if (number < 2) { + System.out.println("Количество гостей не может быть меньше 1. Вероятно вы ошиблись."); + } else { + return number; + } } }