From 28e2a95d91deb51ace995035087259d495e5f5f2 Mon Sep 17 00:00:00 2001 From: Karakaten Date: Wed, 5 Oct 2022 17:22:29 +0400 Subject: [PATCH 01/21] commit --- .idea/.gitignore | 3 + .idea/codeStyles/Project.xml | 123 +++++++++++++++++++++++++++ .idea/codeStyles/codeStyleConfig.xml | 5 ++ .idea/compiler.xml | 6 ++ .idea/gradle.xml | 17 ++++ .idea/misc.xml | 10 +++ .idea/vcs.xml | 6 ++ src/main/java/Calculator.java | 22 +++++ src/main/java/Main.java | 7 +- src/main/java/Product.java | 20 +++++ 10 files changed, 216 insertions(+), 3 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/Product.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..aa1559a --- /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..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..fdc5579 --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,22 @@ +public class Calculator { + + private String bill = ""; + private double finalPrice = 0.0; + private int countPerson = 0; + + public Calculator(int countPerson) { + this.countPerson = countPerson; + } + + public void add(Product product) { + finalPrice += product.getPrice(); + bill += product.getName() + " " + product.getPrice() + "\n"; + } + + public String calculate() { + // finalePrice/countPerson + double priceOfPerson = finalPrice / countPerson; + return bill + "\n" + "Итого: " + finalPrice + "\n" + "Цена с человека: " + priceOfPerson; + } + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c4..da891dc 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,8 +1,9 @@ +import java.util.Scanner; + public class Main { public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + } } + diff --git a/src/main/java/Product.java b/src/main/java/Product.java new file mode 100644 index 0000000..f6df5fa --- /dev/null +++ b/src/main/java/Product.java @@ -0,0 +1,20 @@ +public class Product { + private String name; + private Double price; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } +} From 18e82aff952c4c4a5969d51388f7a08e80fd8698 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 24 Oct 2022 13:57:24 +0300 Subject: [PATCH 02/21] Update Main.java --- src/main/java/Main.java | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index da891dc..5a4c373 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,40 @@ import java.util.Scanner; public class Main { - public static void main(String[] args) { + Scanner scanner = new Scanner(System.in); + Calculator calculator = new Calculator(); + + while (true) { + System.out.println("На скольких человек разделить счет?"); + int scanPerson = scanner.nextInt(); + + if (scanPerson == 1) { + System.out.println("Подсчет не нужен"); + break; + } else if (scanPerson < 1) { + System.out.println("Ошибка. Введите корректное значение."); + } else if (scanPerson > 1) { + System.out.println("Количество человек: " + scanPerson); + break; + } + + } + + while (true) { + Product product = new Product(); + System.out.println("Введите название товара"); + product.setNameOfProduct(scanner.next()); + System.out.println("Введите стоимость товара в формате 00,00"); + product.setCost(scanner.nextDouble()); + System.out.println("Все? Да/Нет"); + if (scanner.next().equals("Да")) { + break; + } + calculator.setBill(product); + } + + calculator.calculate(); } } - From 64686f2a469715d9786ec48f65154ee89d4b250c Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 24 Oct 2022 13:57:46 +0300 Subject: [PATCH 03/21] Update Calculator.java --- src/main/java/Calculator.java | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index fdc5579..c67bb5e 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -1,22 +1,18 @@ public class Calculator { - private String bill = ""; - private double finalPrice = 0.0; - private int countPerson = 0; + String bill = ""; + double finalPrice = 0.00; + int countPerson = 0; - public Calculator(int countPerson) { - this.countPerson = countPerson; - } + public void setBill(Product product) { + finalPrice += product.getCost(); + bill = product.getNameOfProduct() + product.getCost(); + } - public void add(Product product) { - finalPrice += product.getPrice(); - bill += product.getName() + " " + product.getPrice() + "\n"; - } public String calculate() { - // finalePrice/countPerson double priceOfPerson = finalPrice / countPerson; - return bill + "\n" + "Итого: " + finalPrice + "\n" + "Цена с человека: " + priceOfPerson; + return "Итого: " + bill + "Денег с человека:" + priceOfPerson; } - } + From 0d163183dcd2392833daa8ec79cc94a537c1a323 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 24 Oct 2022 13:58:14 +0300 Subject: [PATCH 04/21] Update Product.java --- src/main/java/Product.java | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/main/java/Product.java b/src/main/java/Product.java index f6df5fa..5364825 100644 --- a/src/main/java/Product.java +++ b/src/main/java/Product.java @@ -1,20 +1,23 @@ public class Product { - private String name; - private Double price; - public String getName() { - return name; + public String getNameOfProduct() { + return nameOfProduct; } - public void setName(String name) { - this.name = name; + public void setNameOfProduct(String nameOfProduct) { + this.nameOfProduct = nameOfProduct; } - public Double getPrice() { - return price; + public double getCost() { + return cost; } - public void setPrice(Double price) { - this.price = price; + public void setCost(double cost) { + this.cost = cost; } + + private String nameOfProduct; + private double cost; + + } From 42ecc419b472aa54a79a71fe4d25034961ac4cb0 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:06:52 +0300 Subject: [PATCH 05/21] Update Main.java --- src/main/java/Main.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 5a4c373..2e8b63a 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,7 +5,7 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Calculator calculator = new Calculator(); - + Product product = new Product(); while (true) { System.out.println("На скольких человек разделить счет?"); int scanPerson = scanner.nextInt(); @@ -17,13 +17,14 @@ public static void main(String[] args) { System.out.println("Ошибка. Введите корректное значение."); } else if (scanPerson > 1) { System.out.println("Количество человек: " + scanPerson); + product.setCountPerson(scanPerson); break; } - + } while (true) { - Product product = new Product(); + System.out.println("Введите название товара"); product.setNameOfProduct(scanner.next()); System.out.println("Введите стоимость товара в формате 00,00"); From 86f031c61844c31a8c7fe88c8afaeebf25f987a4 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:07:11 +0300 Subject: [PATCH 06/21] Update Calculator.java --- src/main/java/Calculator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index c67bb5e..c7c2cd8 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -7,6 +7,7 @@ public class Calculator { public void setBill(Product product) { finalPrice += product.getCost(); bill = product.getNameOfProduct() + product.getCost(); + countPerson = product.getCountPerson(); } @@ -15,4 +16,3 @@ public String calculate() { return "Итого: " + bill + "Денег с человека:" + priceOfPerson; } } - From c2fbc1bade9e83696c126f2f8bf1fae0d5e9af59 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 24 Oct 2022 14:07:31 +0300 Subject: [PATCH 07/21] Update Product.java --- src/main/java/Product.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/Product.java b/src/main/java/Product.java index 5364825..f823417 100644 --- a/src/main/java/Product.java +++ b/src/main/java/Product.java @@ -19,5 +19,15 @@ public void setCost(double cost) { private String nameOfProduct; private double cost; + public int getCountPerson() { + return countPerson; + } + + public void setCountPerson(int countPerson) { + this.countPerson = countPerson; + } + + private int countPerson; + } From 1e409ea00facfbc797d0fb77ec5bb662abaa24f0 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 24 Oct 2022 16:24:12 +0300 Subject: [PATCH 08/21] Update Calculator.java --- src/main/java/Calculator.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index c7c2cd8..05b7047 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -1,18 +1,19 @@ public class Calculator { String bill = ""; - double finalPrice = 0.00; + double finalPrice = 0; int countPerson = 0; public void setBill(Product product) { + bill += (product.getNameOfProduct() + "\n" + product.getCost()) + "\n"; finalPrice += product.getCost(); - bill = product.getNameOfProduct() + product.getCost(); - countPerson = product.getCountPerson(); + countPerson += product.getCountPerson(); } - public String calculate() { + public void calculate() { double priceOfPerson = finalPrice / countPerson; - return "Итого: " + bill + "Денег с человека:" + priceOfPerson; + System.out.println("Общий чек: " + "\n" + bill + "\n" + "Денег с человека:" + "\n" + priceOfPerson + " рублей"); } + } From 0d2043ea824329a697160d2d91cbd685e2f9eebb Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Tue, 25 Oct 2022 09:45:52 +0300 Subject: [PATCH 09/21] Update Calculator.java --- src/main/java/Calculator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 05b7047..e8e8f29 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -7,7 +7,7 @@ public class Calculator { public void setBill(Product product) { bill += (product.getNameOfProduct() + "\n" + product.getCost()) + "\n"; finalPrice += product.getCost(); - countPerson += product.getCountPerson(); + countPerson = product.getCountPerson(); } From a5befd3468b879a0cd2d3bb22534a7460d8a8cd3 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Tue, 25 Oct 2022 09:46:16 +0300 Subject: [PATCH 10/21] Update Product.java --- src/main/java/Product.java | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/main/java/Product.java b/src/main/java/Product.java index f823417..8e27dd9 100644 --- a/src/main/java/Product.java +++ b/src/main/java/Product.java @@ -1,5 +1,17 @@ public class Product { + private String nameOfProduct; + private double cost; + + public int getCountPerson() { + return countPerson; + } + + public void setCountPerson(int countPerson) { + this.countPerson = countPerson; + } + + private int countPerson; public String getNameOfProduct() { return nameOfProduct; } @@ -15,19 +27,4 @@ public double getCost() { public void setCost(double cost) { this.cost = cost; } - - private String nameOfProduct; - private double cost; - - public int getCountPerson() { - return countPerson; - } - - public void setCountPerson(int countPerson) { - this.countPerson = countPerson; - } - - private int countPerson; - - } From 066c7c2b3038033e4d925901f460d8ff1e4b6068 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Tue, 25 Oct 2022 09:46:41 +0300 Subject: [PATCH 11/21] Update Main.java --- src/main/java/Main.java | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 2e8b63a..d9a4081 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,37 +5,38 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Calculator calculator = new Calculator(); - Product product = new Product(); + while (true) { + Product product = new Product(); System.out.println("На скольких человек разделить счет?"); int scanPerson = scanner.nextInt(); if (scanPerson == 1) { System.out.println("Подсчет не нужен"); - break; + System.exit(0); } else if (scanPerson < 1) { System.out.println("Ошибка. Введите корректное значение."); } else if (scanPerson > 1) { - System.out.println("Количество человек: " + scanPerson); product.setCountPerson(scanPerson); - break; - } + System.out.println("Количество человек: " + scanPerson); - } + } + while (true) { - while (true) { + System.out.println("Введите название товара"); + product.setNameOfProduct(scanner.next()); + System.out.println("Введите стоимость товара в формате 00,00"); + product.setCost(scanner.nextDouble()); + calculator.setBill(product); + System.out.println("Завершить? Нажмите любой символ, чтобы продолжить"); + if (scanner.next().equalsIgnoreCase("Завершить")) { + break; + } - System.out.println("Введите название товара"); - product.setNameOfProduct(scanner.next()); - System.out.println("Введите стоимость товара в формате 00,00"); - product.setCost(scanner.nextDouble()); - System.out.println("Все? Да/Нет"); - if (scanner.next().equals("Да")) { - break; } - calculator.setBill(product); - } + calculator.calculate(); + System.exit(0); - calculator.calculate(); + } } } From eaf62df43c8c76686a2d38d294957cf2448309f2 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:20:03 +0300 Subject: [PATCH 12/21] Update Main.java --- src/main/java/Main.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index d9a4081..a067e20 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -7,7 +7,7 @@ public static void main(String[] args) { Calculator calculator = new Calculator(); while (true) { - Product product = new Product(); + System.out.println("На скольких человек разделить счет?"); int scanPerson = scanner.nextInt(); @@ -16,13 +16,14 @@ public static void main(String[] args) { System.exit(0); } else if (scanPerson < 1) { System.out.println("Ошибка. Введите корректное значение."); - } else if (scanPerson > 1) { - product.setCountPerson(scanPerson); + } else { + calculator.setCountPerson(scanPerson); System.out.println("Количество человек: " + scanPerson); } + } while (true) { - + Product product = new Product(); System.out.println("Введите название товара"); product.setNameOfProduct(scanner.next()); System.out.println("Введите стоимость товара в формате 00,00"); @@ -39,4 +40,3 @@ public static void main(String[] args) { } } -} From 61a9d9dcbd15c32075cf3bb0c3bb86320eecbf4d Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Tue, 25 Oct 2022 12:38:10 +0300 Subject: [PATCH 13/21] Update Calculator.java --- src/main/java/Calculator.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index e8e8f29..c53fcd9 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -3,17 +3,23 @@ public class Calculator { String bill = ""; double finalPrice = 0; int countPerson = 0; + + public void setCountPerson(int countPerson) { + this.countPerson = countPerson; + } + public void setBill(Product product) { bill += (product.getNameOfProduct() + "\n" + product.getCost()) + "\n"; finalPrice += product.getCost(); - countPerson = product.getCountPerson(); + } public void calculate() { double priceOfPerson = finalPrice / countPerson; - System.out.println("Общий чек: " + "\n" + bill + "\n" + "Денег с человека:" + "\n" + priceOfPerson + " рублей"); + System.out.println("Количество персон: " + countPerson + "\n" + "Общий чек: " + + "\n" + bill + "\n" + "Денег с человека:" + "\n" + priceOfPerson + " рублей"); } } From 3c5d7487c745b788cd96e2bd1abee4bb1257edcf Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Wed, 26 Oct 2022 15:11:34 +0300 Subject: [PATCH 14/21] Update Calculator.java --- src/main/java/Calculator.java | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index c53fcd9..9e1f7bc 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -3,23 +3,36 @@ public class Calculator { String bill = ""; double finalPrice = 0; int countPerson = 0; - + + double priceOfPerson = 0; public void setCountPerson(int countPerson) { this.countPerson = countPerson; } - + public void setBill(Product product) { - bill += (product.getNameOfProduct() + "\n" + product.getCost()) + "\n"; + bill += (product.getNameOfProduct() + " " + product.getCost()) + "\n"; finalPrice += product.getCost(); } - + public String math() { + String rubles = ""; + if (priceOfPerson < 5 || priceOfPerson % 10 > 1) { + rubles = "рубля"; + } else if (priceOfPerson % 10 == 0 || priceOfPerson >= 6) { + rubles = "рублей"; + } else if (priceOfPerson % 10 == 1 || priceOfPerson == 1){ + rubles = "рубль"; + } + return rubles; + } public void calculate() { - double priceOfPerson = finalPrice / countPerson; + priceOfPerson = finalPrice / countPerson; System.out.println("Количество персон: " + countPerson + "\n" + "Общий чек: " + - "\n" + bill + "\n" + "Денег с человека:" + "\n" + priceOfPerson + " рублей"); + "\n" + bill + "\n" + "Денег с человека:" + "\n" + String.format("%.2f", priceOfPerson) + " " + math()); } + + } From a76c9b783b0a1f7faf276de294f1f9fe1d9d1ffc Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Wed, 26 Oct 2022 15:11:58 +0300 Subject: [PATCH 15/21] Update Main.java --- src/main/java/Main.java | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a067e20..4ce140b 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -5,24 +5,18 @@ public static void main(String[] args) { Scanner scanner = new Scanner(System.in); Calculator calculator = new Calculator(); - + System.out.println("На скольких человек разделить счет?"); + int scanPerson = scanner.nextInt(); + calculator.setCountPerson(scanPerson); while (true) { - System.out.println("На скольких человек разделить счет?"); - int scanPerson = scanner.nextInt(); - if (scanPerson == 1) { System.out.println("Подсчет не нужен"); System.exit(0); } else if (scanPerson < 1) { System.out.println("Ошибка. Введите корректное значение."); + System.exit(0); } else { - calculator.setCountPerson(scanPerson); - System.out.println("Количество человек: " + scanPerson); - - } - } - while (true) { Product product = new Product(); System.out.println("Введите название товара"); product.setNameOfProduct(scanner.next()); @@ -32,11 +26,10 @@ public static void main(String[] args) { System.out.println("Завершить? Нажмите любой символ, чтобы продолжить"); if (scanner.next().equalsIgnoreCase("Завершить")) { break; - } - } + } + } calculator.calculate(); - System.exit(0); - } } +} From f04d0c2ceda002d5cf8075e132a65694b17caef9 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Wed, 26 Oct 2022 15:12:19 +0300 Subject: [PATCH 16/21] Update Product.java --- src/main/java/Product.java | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/main/java/Product.java b/src/main/java/Product.java index 8e27dd9..a353d0a 100644 --- a/src/main/java/Product.java +++ b/src/main/java/Product.java @@ -3,15 +3,7 @@ public class Product { private String nameOfProduct; private double cost; - public int getCountPerson() { - return countPerson; - } - - public void setCountPerson(int countPerson) { - this.countPerson = countPerson; - } - private int countPerson; public String getNameOfProduct() { return nameOfProduct; } @@ -27,4 +19,5 @@ public double getCost() { public void setCost(double cost) { this.cost = cost; } + } From 7f37eeee955d05a8b5ce35cce8974082cc4dbbcf Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:56:34 +0300 Subject: [PATCH 17/21] Update Calculator.java --- src/main/java/Calculator.java | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 9e1f7bc..47dfdb0 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -13,26 +13,30 @@ public void setCountPerson(int countPerson) { public void setBill(Product product) { bill += (product.getNameOfProduct() + " " + product.getCost()) + "\n"; finalPrice += product.getCost(); - - } + } public String math() { - String rubles = ""; - if (priceOfPerson < 5 || priceOfPerson % 10 > 1) { - rubles = "рубля"; - } else if (priceOfPerson % 10 == 0 || priceOfPerson >= 6) { - rubles = "рублей"; - } else if (priceOfPerson % 10 == 1 || priceOfPerson == 1){ - rubles = "рубль"; + String rubles = "руб"; + if (priceOfPerson > 10 && priceOfPerson <10 ) { + return rubles + "лей"; + } switch ((int) priceOfPerson % 10) { + case 1: { + return rubles + "ль"; + } + case 2: + case 3: + case 4: { + return rubles + "ля"; + } + default: { + return rubles + "лей"; + } } - return rubles; } + public void calculate() { priceOfPerson = finalPrice / countPerson; System.out.println("Количество персон: " + countPerson + "\n" + "Общий чек: " + "\n" + bill + "\n" + "Денег с человека:" + "\n" + String.format("%.2f", priceOfPerson) + " " + math()); } - - - } From 27383aa0b46ab805280117b736b96a5848f73b87 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:56:56 +0300 Subject: [PATCH 18/21] Update Main.java --- src/main/java/Main.java | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 4ce140b..a7b5417 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,35 +1,37 @@ import java.util.Scanner; public class Main { + static Scanner scanner = new Scanner(System.in); public static void main(String[] args) { - Scanner scanner = new Scanner(System.in); + Calculator calculator = new Calculator(); System.out.println("На скольких человек разделить счет?"); - int scanPerson = scanner.nextInt(); - calculator.setCountPerson(scanPerson); - while (true) { + int scanPerson; + + while (true) { + scanPerson = scanner.nextInt(); if (scanPerson == 1) { System.out.println("Подсчет не нужен"); System.exit(0); } else if (scanPerson < 1) { System.out.println("Ошибка. Введите корректное значение."); - System.exit(0); - } else { - Product product = new Product(); - System.out.println("Введите название товара"); - product.setNameOfProduct(scanner.next()); - System.out.println("Введите стоимость товара в формате 00,00"); - product.setCost(scanner.nextDouble()); - calculator.setBill(product); - System.out.println("Завершить? Нажмите любой символ, чтобы продолжить"); - if (scanner.next().equalsIgnoreCase("Завершить")) { - break; - } - } + } else break; } - calculator.calculate(); + + calculator.setCountPerson(scanPerson); + do { + Product product = new Product(); + System.out.println("Введите название товара"); + scanner.nextLine(); + product.setNameOfProduct(scanner.nextLine()); + System.out.println("Введите стоимость товара в формате 00,00"); + product.setCost(scanner.nextDouble()); + calculator.setBill(product); + System.out.println("Завершить? Нажмите любой символ, чтобы продолжить"); + } while (!scanner.next().equalsIgnoreCase("Завершить")); + calculator.calculate(); } } From 6d6c757193802ec4ee06e3ee5b76df820bb32dab Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:57:19 +0300 Subject: [PATCH 19/21] Update Product.java From 7ba8870eb30e1ac731529073ff4f672e756cf647 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Fri, 28 Oct 2022 16:44:42 +0300 Subject: [PATCH 20/21] Update Calculator.java --- src/main/java/Calculator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 47dfdb0..9b99d0f 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -17,7 +17,7 @@ public void setBill(Product product) { public String math() { String rubles = "руб"; - if (priceOfPerson > 10 && priceOfPerson <10 ) { + if (priceOfPerson > 10 && priceOfPerson <20 ) { return rubles + "лей"; } switch ((int) priceOfPerson % 10) { case 1: { From 18fad59c299e96691ffe16572bb9a1286b05fc20 Mon Sep 17 00:00:00 2001 From: Karakaten <102169385+Karakaten@users.noreply.github.com> Date: Mon, 31 Oct 2022 11:33:05 +0300 Subject: [PATCH 21/21] Update Main.java --- src/main/java/Main.java | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a7b5417..a104a17 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 { @@ -9,15 +10,20 @@ public static void main(String[] args) { System.out.println("На скольких человек разделить счет?"); int scanPerson; - while (true) { - scanPerson = scanner.nextInt(); - if (scanPerson == 1) { - System.out.println("Подсчет не нужен"); - System.exit(0); - } else if (scanPerson < 1) { - System.out.println("Ошибка. Введите корректное значение."); - } else break; + + if (scanner.hasNextInt()) { + scanPerson = scanner.nextInt(); + if (scanPerson == 1) { + System.out.println("Подсчет не нужен"); + System.exit(0); + } else if (scanPerson < 1) { + System.out.println("Ошибка. Введите корректное значение."); + } else break; + } else { + System.out.println("Введите корректное значение"); + scanner.nextLine(); + } } calculator.setCountPerson(scanPerson); @@ -27,11 +33,22 @@ public static void main(String[] args) { scanner.nextLine(); product.setNameOfProduct(scanner.nextLine()); System.out.println("Введите стоимость товара в формате 00,00"); - product.setCost(scanner.nextDouble()); + product.setCost(inputPrice()); calculator.setBill(product); System.out.println("Завершить? Нажмите любой символ, чтобы продолжить"); } while (!scanner.next().equalsIgnoreCase("Завершить")); calculator.calculate(); } + + static double price = 0.0; + public static double inputPrice() { + try { + price = scanner.nextDouble(); + } catch (InputMismatchException exception) { + System.out.println("Введите корректное значение"); + scanner.nextLine(); + inputPrice(); + } return price; + } }