From 9a0767a6907e03d4315078c71ed8901c62b6e489 Mon Sep 17 00:00:00 2001 From: cherryblazer69 <111906221+cherryblazer69@users.noreply.github.com> Date: 2022年8月28日 16:35:15 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 3 ++ .idea/codeStyles/Project.xml | 10 +++++ .idea/codeStyles/codeStyleConfig.xml | 5 +++ .idea/compiler.xml | 6 +++ .idea/gradle.xml | 17 +++++++++ .idea/misc.xml | 5 +++ .idea/vcs.xml | 6 +++ src/main/java/Calculator.java | 57 ++++++++++++++++++++++++++++ src/main/java/Main.java | 27 +++++++++++-- 9 files changed, 132 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 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..1bec35e --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,10 @@ + + + + + + + + + + \ 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..611e7c8 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..bb614ff --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ 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..c4d76f7 --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,57 @@ +import java.util.Scanner; + +public class Calculator { +//класс и метод подсчета общей стоимости товара + public void calculate(int guests) { + String food = "Dobavlennie tovari: \n"; + Double price = 0.0; + while (true) { + System.out.println("Vvedite nazvanie produkta ili zavershit: "); + Scanner scanner = new Scanner(System.in); + String inputFood = scanner.next(); +//если ничего не добавлено и введено "завершить" + if (inputFood.equalsIgnoreCase("Zavershit") && food.equals("Dobavlennie tovari: \n")) { + break; + } else if (inputFood.equalsIgnoreCase("Zavershit")) { + System.out.println(food); + System.out.println("Kagdiy chelovek zaplatit: " + String.format("%.2f", price / guests) + " " + getRubleAddition(price / guests)); + break; + + } else { + + System.out.println("Vvedite cenu tovara [rub.cop]"); + Double inputPrice = scanner.nextDouble(); + if (inputPrice>0) { + + food = food + inputFood + "\n"; + price = price + inputPrice; +// System.out.println("Tovar " + inputFood + " Dobavlen uspeshno, ego cena sostavlaet: " + inputPrice); + System.out.println("Tovar " + inputFood + " Dobavlen uspeshno, ego cena sostavlaet: " + inputPrice + " " + getRubleAddition(inputPrice)); + } + else { +//случай когда цена товара меньше 0 + System.out.println("Cena tovara ne mozhet bit menshe 0!"); + } + } + } + } +//метод для написания рублей в правильном падеже + public String getRubleAddition(Double num) { + int preLastDigit = (int) (num % 100 / 10); + if (preLastDigit == 1) { + return "rubley"; + } + + switch ((int) (num % 10)) { + case 1: + return "rubl"; + case 2: + case 3: + case 4: + return "rublya"; + default: + return "rubley"; + } + } + +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..a2f9a16 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,27 @@ -public class Main { +import java.util.Scanner; +public class Main { +//обработка количества гостей public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + Scanner scanner = new Scanner(System.in); + System.out.println("Vvedite kolichestvo gostey: "); + while (true) { + int guests = scanner.nextInt(); + if (guests <= 0) { + System.out.println("Vvedite nekorrektnoe znachenie,vvedite znachenie bolshe 1: "); + } + if (guests == 1) { + System.out.println("A zachem togta schitat? vvedite znachenie bolshe 1: "); + } + if (guests> 1) { + System.out.println("Seyachas pschitaem!"); + Calculator calculator = new Calculator(); + calculator.calculate(guests); + + break; + } + } + } } + From c1e5e640b8811a1d2feb090dfb5e508e5e5a39cf Mon Sep 17 00:00:00 2001 From: cherryblazer69 <111906221+cherryblazer69@users.noreply.github.com> Date: 2022年8月29日 20:34:34 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D0=BE=D0=B5=20?= =?UTF-8?q?=D0=B4=D0=B7=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=20=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D0=B2=D0=BE=D0=B3=D0=BE=20=D1=80=D0=B5=D0=B2=D1=8C=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 19 +++++++++++++------ src/main/java/Main.java | 19 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index c4d76f7..1714477 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -1,7 +1,7 @@ import java.util.Scanner; public class Calculator { -//класс и метод подсчета общей стоимости товара + //класс и метод подсчета общей стоимости товара public void calculate(int guests) { String food = "Dobavlennie tovari: \n"; Double price = 0.0; @@ -20,22 +20,29 @@ public void calculate(int guests) { } else { System.out.println("Vvedite cenu tovara [rub.cop]"); - Double inputPrice = scanner.nextDouble(); - if (inputPrice>0) { + Double inputPrice; + //программа принимала значение стоимости через точку,но при вводе запятой крашилась, в данном блоке это исправлено + try { + inputPrice = scanner.nextDouble(); + } catch (Exception e) { + System.out.println("Vvedite znachenie zanovo i korrektno!"); + continue; + } + if (inputPrice> 0) { food = food + inputFood + "\n"; price = price + inputPrice; // System.out.println("Tovar " + inputFood + " Dobavlen uspeshno, ego cena sostavlaet: " + inputPrice); System.out.println("Tovar " + inputFood + " Dobavlen uspeshno, ego cena sostavlaet: " + inputPrice + " " + getRubleAddition(inputPrice)); - } - else { + } else { //случай когда цена товара меньше 0 System.out.println("Cena tovara ne mozhet bit menshe 0!"); } } } } -//метод для написания рублей в правильном падеже + + //метод для написания рублей в правильном падеже public String getRubleAddition(Double num) { int preLastDigit = (int) (num % 100 / 10); if (preLastDigit == 1) { diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a2f9a16..b84f176 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,19 +1,24 @@ import java.util.Scanner; public class Main { -//обработка количества гостей + //обработка количества гостей public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); System.out.println("Vvedite kolichestvo gostey: "); while (true) { - int guests = scanner.nextInt(); + Scanner scanner = new Scanner(System.in); + int guests = 0; + // условие проверки ввода текста при запросе количества гостей + try { + guests = scanner.nextInt(); + } catch (Exception ex) { + System.out.println("Vvedeno nekorektnoe znachenie gostey, vvedite cifru"); + continue; + } if (guests <= 0) { System.out.println("Vvedite nekorrektnoe znachenie,vvedite znachenie bolshe 1: "); - } - if (guests == 1) { + } else if (guests == 1) { System.out.println("A zachem togta schitat? vvedite znachenie bolshe 1: "); - } - if (guests> 1) { + } else { System.out.println("Seyachas pschitaem!"); Calculator calculator = new Calculator(); calculator.calculate(guests); From e714fab688063738ee667acea006f7d267dfddf3 Mon Sep 17 00:00:00 2001 From: cherryblazer69 <111906221+cherryblazer69@users.noreply.github.com> Date: 2022年8月31日 16:32:13 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=94=D0=B7=20=D0=BF=D0=BE=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B3=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B2=D1=8C=D1=8E,=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80?= =?UTF-8?q?=D1=8C=20=D1=86=D0=B5=D0=BD=D0=B0=20=D1=82=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=80=D0=B0=20=D0=BC=D0=BE=D0=B6=D0=B5=D1=82=20=D0=B2=D0=B2?= =?UTF-8?q?=D0=BE=D0=B4=D0=B8=D1=82=D1=8C=D1=81=D1=8F=20=D0=B8=20=D1=87?= =?UTF-8?q?=D0=B5=D1=80=D0=B5=D0=B7=20=D1=82=D0=BE=D1=87=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B8=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D0=B7=D0=B0=D0=BF?= =?UTF-8?q?=D1=8F=D1=82=D1=83=D1=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/gradle.xml | 2 ++ src/main/java/Calculator.java | 13 ++++++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.idea/gradle.xml b/.idea/gradle.xml index 611e7c8..40bd79d 100644 --- a/.idea/gradle.xml +++ b/.idea/gradle.xml @@ -4,8 +4,10 @@ + + diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 1714477..57a9cc1 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -20,19 +20,22 @@ public void calculate(int guests) { } else { System.out.println("Vvedite cenu tovara [rub.cop]"); - Double inputPrice; - //программа принимала значение стоимости через точку,но при вводе запятой крашилась, в данном блоке это исправлено + Double inputPrice = 0.0; + String inputString; + // программа принимала значение стоимости через точку,но при вводе запятой крашилась, теперь программа принимает как точку, так и запятую, при вводе + // некорректного значения цены выводится сообщение о том, что значение введено некорректно try { - inputPrice = scanner.nextDouble(); + inputString = scanner.next(); + inputString = inputString.replace(",", "."); + inputPrice = Double.valueOf(inputString); } catch (Exception e) { - System.out.println("Vvedite znachenie zanovo i korrektno!"); + System.out.println("Vvedite znachenie stoimosti zanovo i korrektno v ukazanom formate!"); continue; } if (inputPrice> 0) { food = food + inputFood + "\n"; price = price + inputPrice; -// System.out.println("Tovar " + inputFood + " Dobavlen uspeshno, ego cena sostavlaet: " + inputPrice); System.out.println("Tovar " + inputFood + " Dobavlen uspeshno, ego cena sostavlaet: " + inputPrice + " " + getRubleAddition(inputPrice)); } else { //случай когда цена товара меньше 0 AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル