From 59db1e6847a11d5a6ef258e474cd0828a0a74cab Mon Sep 17 00:00:00 2001 From: lx Date: 2022年8月27日 12:18:31 +0300 Subject: [PATCH 1/4] Version 1.0 --- .idea/.gitignore | 3 +++ .idea/compiler.xml | 6 ++++++ .idea/gradle.xml | 18 ++++++++++++++++++ .idea/misc.xml | 9 +++++++++ .idea/vcs.xml | 6 ++++++ src/main/java/Calculator.java | 34 ++++++++++++++++++++++++++++++++++ src/main/java/Main.java | 29 +++++++++++++++++++++++++++++ 7 files changed, 105 insertions(+) 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 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/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..5d10be7 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ 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..eb037a4 --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,34 @@ +import java.util.Scanner; +public class Calculator { + + static void calculate(int people) { + String food = ""; + double price = 0.0; + + while (true) { + System.out.println("Введите название продукта, для выхода введите [Завершить]"); + Scanner scanner = new Scanner(System.in); + String inputFood = scanner.next(); + + if (inputFood.equalsIgnoreCase("Завершить")) { + break; + } else { + System.out.println("Введите цену в формате [руб,коп]"); + double inputPrice = scanner.nextDouble(); + food = food + inputFood + "\n"; + + if (inputPrice <= 0){ + System.out.println("Неверная цена"); + } else { + price = price + inputPrice; + } + } + + } + int rouble = (int) Math.round(price); + System.out.println("Добавленные товары:\n" + food); + String message = "Каждый человек должен заплатить %.2f" + " " + Main.declination(rouble); + System.out.println(String.format(message, (price / people))); + } + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 964dbb0..9baae0b 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,6 +1,35 @@ +import java.util.Scanner; public class Main { public static void main(String[] args) { // ваш код начнется здесь + int people; + while (true) { + System.out.println("На сколько человек нужно разделить счет?"); + Scanner scanner = new Scanner(System.in); + people = scanner.nextInt(); + if (people>= 2) { + break; + } else { + System.out.println("Неверное значение"); + } + } + + Calculator calculator = new Calculator(); + Calculator.calculate(people); + + } + public static String declination(int rouble) { + switch (rouble % 10) { + case 1: + return "рубль"; + case 2: + case 3: + case 4: + return "рубля"; + default: + return "рублей"; + } } } + From 6c7437afa2cc507961e5d9e86f7450006965397b Mon Sep 17 00:00:00 2001 From: lx Date: 2022年8月27日 19:07:48 +0300 Subject: [PATCH 2/4] Version 1.1 --- .idea/.name | 1 + .idea/codeStyles/Project.xml | 123 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ src/main/java/Calculator.java | 16 ++-- 4 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 .idea/.name create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/codeStyles/codeStyleConfig.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..05b5864 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +BillCalculator \ No newline at end of file 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 eb037a4..e41f7fa 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -1,3 +1,4 @@ +import java.util.InputMismatchException; import java.util.Scanner; public class Calculator { @@ -14,14 +15,13 @@ static void calculate(int people) { break; } else { System.out.println("Введите цену в формате [руб,коп]"); - double inputPrice = scanner.nextDouble(); + double inputPrice = 0; + try {inputPrice = scanner.nextDouble();} + catch (InputMismatchException e) { + System.out.println("Неверное значение"); + } food = food + inputFood + "\n"; - - if (inputPrice <= 0){ - System.out.println("Неверная цена"); - } else { - price = price + inputPrice; - } + price = price + inputPrice; } } @@ -32,3 +32,5 @@ static void calculate(int people) { } } + + From ba850ef9fc6dc174da7c74256a276afadeed5969 Mon Sep 17 00:00:00 2001 From: lx Date: 2022年8月28日 23:27:50 +0300 Subject: [PATCH 3/4] Version 1.2 --- src/main/java/Calculator.java | 25 +++++++++++++++++-------- src/main/java/Main.java | 12 ++++++++---- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index e41f7fa..f4a8c76 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -14,14 +14,8 @@ static void calculate(int people) { if (inputFood.equalsIgnoreCase("Завершить")) { break; } else { - System.out.println("Введите цену в формате [руб,коп]"); - double inputPrice = 0; - try {inputPrice = scanner.nextDouble();} - catch (InputMismatchException e) { - System.out.println("Неверное значение"); - } food = food + inputFood + "\n"; - price = price + inputPrice; + price = price + price(); } } @@ -31,6 +25,21 @@ static void calculate(int people) { System.out.println(String.format(message, (price / people))); } -} + + static double price() { + while (true) { + System.out.println("Введите цену в формате [руб,коп]"); + double inputPrice = 0; + try { + double price = 0.0; + Scanner scanner = new Scanner(System.in); + inputPrice = scanner.nextDouble(); + return inputPrice; + } catch (InputMismatchException e) { + System.out.println("Неверное значение"); + } + } + } +} \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 9baae0b..50529f1 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,3 +1,4 @@ +import java.util.InputMismatchException; import java.util.Scanner; public class Main { @@ -7,10 +8,13 @@ public static void main(String[] args) { while (true) { System.out.println("На сколько человек нужно разделить счет?"); Scanner scanner = new Scanner(System.in); - people = scanner.nextInt(); - if (people>= 2) { - break; - } else { + try { + people = scanner.nextInt(); + if (people>= 2) { + break; + } + } + catch (InputMismatchException e) { System.out.println("Неверное значение"); } } From 2e7e493094f3b083c044268add990cad0250e0a1 Mon Sep 17 00:00:00 2001 From: lx Date: 2022年8月28日 23:49:53 +0300 Subject: [PATCH 4/4] Version 1.3 --- src/main/java/Calculator.java | 6 +++++- src/main/java/Main.java | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index f4a8c76..a27f286 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -34,7 +34,11 @@ static double price() { double price = 0.0; Scanner scanner = new Scanner(System.in); inputPrice = scanner.nextDouble(); - return inputPrice; + if (inputPrice <= 0){ + System.out.println("Неверное значение"); + } else { + return inputPrice; + } } catch (InputMismatchException e) { System.out.println("Неверное значение"); } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 50529f1..7d5812c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -12,6 +12,8 @@ public static void main(String[] args) { people = scanner.nextInt(); if (people>= 2) { break; + } else { + System.out.println("Неверное значение"); } } catch (InputMismatchException e) {

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