From e4c5a4667253bfdd33d21645b3bed477d8ff2d84 Mon Sep 17 00:00:00 2001 From: DexMP Date: 2023年9月24日 15:20:04 +0300 Subject: [PATCH 1/9] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B2=D1=8B=D0=B9=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BC=D0=BC=D0=B8=D1=82=20=D1=81=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=B1=D1=80=D0=BE=D1=81=D0=BA=D0=B0=D0=BC=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index db9356a08..401bf4fa1 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,6 +1,43 @@ +import java.util.Scanner; public class Main { public static void main(String[] args) { - System.out.println("Hello world!"); + + // Поздороваемся! + System.out.print("Доброго времени суток!\n" + + "На скольких человек необходимо разделить счёт:"); + + // Переменная хранящая людей (да-да как криокамера) + int humans; + + // Переменная имён продуктов + + // Переменная цен продуктов + Scanner scanner_humans = new Scanner(System.in); + if (scanner_humans.hasNextInt()) { + humans = scanner_humans.nextInt(); + // Проверка на корректное значение человек + correct_humens(humans); + } else { + System.out.println("Возможно вы ввели не число, попробуйте ещё раз!"); + } + } + + private static boolean compliance_check(int humans) { + return humans> 1; + } + + private static void correct_humens(int humans) { + if (compliance_check(humans)){ + + // Дополнительная проверка количества людей, что бы не ударить в грязь лицом перед грамматикой + if(humans == 2 || humans == 3 || humans == 4){ + System.out.print("Записал, " + humans + " человека."); + } else { + System.out.print("Записал, " + humans + " человек."); + } + } else { + System.out.print("Некорректное значение! Количество человек должно быть больше 1"); + } } } \ No newline at end of file From e5bc7b0e1dbd24f1a2f0c49ab5c4f7b0f85431f1 Mon Sep 17 00:00:00 2001 From: DexMP Date: 2023年9月30日 00:18:23 +0300 Subject: [PATCH 2/9] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 22 ++++++++++++++++ src/main/java/Main.java | 47 ++++++++++++++++------------------- src/main/java/Product.java | 10 ++++++++ 3 files changed, 54 insertions(+), 25 deletions(-) create mode 100644 src/main/java/Calculator.java create mode 100644 src/main/java/Product.java diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java new file mode 100644 index 000000000..7b9f153a7 --- /dev/null +++ b/src/main/java/Calculator.java @@ -0,0 +1,22 @@ +public class Calculator { + + double summ; + + + public static int sum(int a, int b) { + return a + b; + } + + public static int subtract(int a, int b) { + return a - b; + } + + public static int multiply(int a, int b) { + return a * b; + } + + public static int divide(int a, int b) { + return a / b; + } + +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 401bf4fa1..55befcf07 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -4,40 +4,37 @@ public class Main { public static void main(String[] args) { // Поздороваемся! - System.out.print("Доброго времени суток!\n" + + System.out.println("Доброго времени суток!\n" + "На скольких человек необходимо разделить счёт:"); // Переменная хранящая людей (да-да как криокамера) int humans; - // Переменная имён продуктов - - // Переменная цен продуктов + // Сканер Scanner scanner_humans = new Scanner(System.in); - if (scanner_humans.hasNextInt()) { - humans = scanner_humans.nextInt(); - // Проверка на корректное значение человек - correct_humens(humans); - } else { - System.out.println("Возможно вы ввели не число, попробуйте ещё раз!"); - } - } - - private static boolean compliance_check(int humans) { - return humans> 1; - } - private static void correct_humens(int humans) { - if (compliance_check(humans)){ - - // Дополнительная проверка количества людей, что бы не ударить в грязь лицом перед грамматикой - if(humans == 2 || humans == 3 || humans == 4){ - System.out.print("Записал, " + humans + " человека."); + // Бесконечный цикл который позволяет нам не вывалиться из программы и спрашивать пользователя количество людей + while (true) { + if (scanner_humans.hasNextInt()) { + humans = scanner_humans.nextInt(); + while (humans <= 1) { + System.out.println("Количество людей должно быть более 1"); + humans = scanner_humans.nextInt(); + if (humans> 1) { + break; + } else { + System.out.println("Введено не число!"); + } + } + break; } else { - System.out.print("Записал, " + humans + " человек."); + System.out.println("Возможно вы ввели не число, попробуйте ещё раз!"); + scanner_humans.nextLine(); } - } else { - System.out.print("Некорректное значение! Количество человек должно быть больше 1"); } + + + + System.out.println(humans); } } \ No newline at end of file diff --git a/src/main/java/Product.java b/src/main/java/Product.java new file mode 100644 index 000000000..567538759 --- /dev/null +++ b/src/main/java/Product.java @@ -0,0 +1,10 @@ +public class Product { + + String productName; + double productPrice; + + public Product(String productName, double productPrice) { + this.productName = productName; + this.productPrice = productPrice; + } +} From dac4cc538c115ec6eacb0ad247df249d6951140e Mon Sep 17 00:00:00 2001 From: DexMP Date: Tue, 3 Oct 2023 16:05:31 +0300 Subject: [PATCH 3/9] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=86?= =?UTF-8?q?=D0=B8=D0=BA=D0=BB=20=D1=81=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=D0=BC=20=D0=BF=D1=80=D0=BE=D0=B4?= =?UTF-8?q?=D1=83=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Calculator.java | 7 +++++ src/main/java/Main.java | 48 ++++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java index 7b9f153a7..9e88783ac 100644 --- a/src/main/java/Calculator.java +++ b/src/main/java/Calculator.java @@ -1,7 +1,14 @@ public class Calculator { double summ; + int a; + int b; + public Calculator(int a, int b) { + this.a = a; + this.b = b; + this.summ = sum(a, b); + } public static int sum(int a, int b) { return a + b; diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 55befcf07..25408161f 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -3,15 +3,19 @@ public class Main { public static void main(String[] args) { - // Поздороваемся! - System.out.println("Доброго времени суток!\n" + - "На скольких человек необходимо разделить счёт:"); - - // Переменная хранящая людей (да-да как криокамера) + // Переменные int humans; + double price; + String products = null; + float summ; - // Сканер + // Сканеры Scanner scanner_humans = new Scanner(System.in); + Scanner scanner_products = new Scanner(System.in); + + // Поздороваемся! + System.out.println("Доброго времени суток!\n" + + "На скольких человек необходимо разделить счёт:"); // Бесконечный цикл который позволяет нам не вывалиться из программы и спрашивать пользователя количество людей while (true) { @@ -20,11 +24,7 @@ public static void main(String[] args) { while (humans <= 1) { System.out.println("Количество людей должно быть более 1"); humans = scanner_humans.nextInt(); - if (humans> 1) { - break; - } else { - System.out.println("Введено не число!"); - } + if (humans> 1) break; } break; } else { @@ -33,8 +33,32 @@ public static void main(String[] args) { } } + System.out.println(humans); + System.out.println("Что вы заказывали:"); - System.out.println(humans); + while (true) { + if (scanner_products.hasNext()) { + // Название + products = scanner_products.nextLine(); + System.out.println("Сколько стоит " + products + ":"); + while (true) { + if (scanner_products.hasNext()) { + // Ценник + price = scanner_products.nextDouble(); + Product product1 = new Product(products, price); + System.out.println(product1.productName + " = " + product1.productPrice); + break; + } else { + System.out.println("Кого ты хочешь обмануть? Вводи сумму:"); + price = scanner_products.nextDouble(); + } + } + break; + } else { + System.out.println("Кажется строка пустая! Попробуйте ещё раз:"); + products = scanner_products.nextLine(); + } + } } } \ No newline at end of file From 22911ef1840599fc969ba13614dab9b0af13dcc5 Mon Sep 17 00:00:00 2001 From: DexMP Date: 2023年10月23日 18:54:12 +0300 Subject: [PATCH 4/9] mini fixed --- src/main/java/Main.java | 54 ++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 19 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 25408161f..97fcb9682 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -3,21 +3,24 @@ public class Main { public static void main(String[] args) { + // Classes + Product product = null; // Переменные int humans; - double price; - String products = null; + double price = 0; + String products; float summ; // Сканеры Scanner scanner_humans = new Scanner(System.in); Scanner scanner_products = new Scanner(System.in); + Scanner scanner_prices = new Scanner(System.in); // Поздороваемся! System.out.println("Доброго времени суток!\n" + "На скольких человек необходимо разделить счёт:"); - // Бесконечный цикл который позволяет нам не вывалиться из программы и спрашивать пользователя количество людей + // Получаем количество людей while (true) { if (scanner_humans.hasNextInt()) { humans = scanner_humans.nextInt(); @@ -34,30 +37,43 @@ public static void main(String[] args) { } System.out.println(humans); - - System.out.println("Что вы заказывали:"); - + System.out.println("Что было в заказе:"); + // Получаем товары while (true) { + // Наименование if (scanner_products.hasNext()) { - // Название products = scanner_products.nextLine(); - System.out.println("Сколько стоит " + products + ":"); - while (true) { - if (scanner_products.hasNext()) { - // Ценник - price = scanner_products.nextDouble(); - Product product1 = new Product(products, price); - System.out.println(product1.productName + " = " + product1.productPrice); + while (products.isEmpty()) { + System.out.println("Нет данных"); + products = scanner_products.nextLine(); + if (!products.isEmpty()) { break; - } else { - System.out.println("Кого ты хочешь обмануть? Вводи сумму:"); + } + } + + System.out.println("Цена товара в формате 'рубли.копейки':"); + + // Цена + if (scanner_prices.hasNextDouble()) { + price = scanner_prices.nextDouble(); + while (price <= 1) { + System.out.println("Значение не может быть меньше 1"); price = scanner_products.nextDouble(); + if (price> 1) { + product = new Product(products, price); + break; + } } + } else { + System.out.println("Неверный формат записи"); + scanner_prices.hasNextDouble(); } - break; } else { - System.out.println("Кажется строка пустая! Попробуйте ещё раз:"); - products = scanner_products.nextLine(); + System.out.println("Не удалось прочитать, попробуйте снова"); + scanner_products.nextLine(); + } + if (product != null) { + System.out.println("Наиименование" + product.productName + "\nЦена: " + product.productPrice); } } } From 2ec38a4c0f1ce8964bc01665126d4bb7133e75fb Mon Sep 17 00:00:00 2001 From: DexMP Date: 2023年10月24日 22:22:25 +0300 Subject: [PATCH 5/9] new changes --- src/main/java/Main.java | 46 ++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 97fcb9682..9baf29d44 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -37,44 +37,38 @@ public static void main(String[] args) { } System.out.println(humans); - System.out.println("Что было в заказе:"); // Получаем товары while (true) { - // Наименование + System.out.println("Название товара:"); if (scanner_products.hasNext()) { products = scanner_products.nextLine(); - while (products.isEmpty()) { - System.out.println("Нет данных"); - products = scanner_products.nextLine(); - if (!products.isEmpty()) { - break; - } - } + if (!products.equalsIgnoreCase("завершить")) { + System.out.println("Название: " + products); + System.out.println("Укажите цену товара в формате рубли.копейки: "); + if (scanner_prices.hasNextDouble()) { + price = scanner_prices.nextDouble(); + while (price <= 0) { + System.out.println("Значение не может быть 0 или меньше!"); + price = scanner_prices.nextDouble(); + if (price> 0) { + System.out.println("Цена: " + price); - System.out.println("Цена товара в формате 'рубли.копейки':"); - - // Цена - if (scanner_prices.hasNextDouble()) { - price = scanner_prices.nextDouble(); - while (price <= 1) { - System.out.println("Значение не может быть меньше 1"); - price = scanner_products.nextDouble(); - if (price> 1) { - product = new Product(products, price); - break; + break; + } } + } else { + System.out.println("Кажется вы указали неверный формат!"); + scanner_prices.hasNextDouble(); } } else { - System.out.println("Неверный формат записи"); - scanner_prices.hasNextDouble(); + // Отсылка на фильм Первому Игроку приготовиться) + System.out.println("Спасибо что играл в мою игру!"); + break; } } else { - System.out.println("Не удалось прочитать, попробуйте снова"); + System.out.println("Не получено данных о товаре!"); scanner_products.nextLine(); } - if (product != null) { - System.out.println("Наиименование" + product.productName + "\nЦена: " + product.productPrice); - } } } } \ No newline at end of file From 32044f1f3465dbcdd38d5f11ac29d646841d02bd Mon Sep 17 00:00:00 2001 From: DexMP Date: 2023年10月25日 00:27:39 +0300 Subject: [PATCH 6/9] mb complete --- src/main/java/Main.java | 46 +++++++++++++++++++++++++++++--------- src/main/java/Product.java | 4 +--- 2 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 9baf29d44..35ea48383 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,15 +1,17 @@ +import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { - // Classes - Product product = null; + // List + ArrayList productsName = new ArrayList(); + // Переменные int humans; - double price = 0; + double price; String products; - float summ; + float summ = 0; // Сканеры Scanner scanner_humans = new Scanner(System.in); @@ -36,14 +38,13 @@ public static void main(String[] args) { } } - System.out.println(humans); // Получаем товары while (true) { System.out.println("Название товара:"); if (scanner_products.hasNext()) { products = scanner_products.nextLine(); if (!products.equalsIgnoreCase("завершить")) { - System.out.println("Название: " + products); + productsName.add(new Product(products)); System.out.println("Укажите цену товара в формате рубли.копейки: "); if (scanner_prices.hasNextDouble()) { price = scanner_prices.nextDouble(); @@ -51,18 +52,25 @@ public static void main(String[] args) { System.out.println("Значение не может быть 0 или меньше!"); price = scanner_prices.nextDouble(); if (price> 0) { - System.out.println("Цена: " + price); - + System.out.println("Цена: " + String.format("%.2f", price)); break; } } + summ += price; + System.out.println("Добавленные товары:"); + for (int i = 0; i < productsName.size(); i++) { + System.out.println("* " + productsName.get(i).productName); + } + System.out.println("Сумма: " + String.format("%.2f", summ)); } else { System.out.println("Кажется вы указали неверный формат!"); scanner_prices.hasNextDouble(); } } else { - // Отсылка на фильм Первому Игроку приготовиться) - System.out.println("Спасибо что играл в мою игру!"); + float forPerson = summ / humans; + int rubles = (int) forPerson; + + System.out.println("Сумма на каждого человека " + String.format("%.2f", forPerson) + " " + grammar(rubles)); break; } } else { @@ -71,4 +79,22 @@ public static void main(String[] args) { } } } + + private static String grammar(int rubles) { + if (lastIndexRub(rubles).equals("0")) { + return "рублей"; + } else if (lastIndexRub(rubles).equals("1")) { + return "рубль"; + } else if (lastIndexRub(rubles).equals("2") || lastIndexRub(rubles).equals("3") || lastIndexRub(rubles).equals("4")) { + return "рубля"; + } else { + return "рублей"; + } + } + + private static String lastIndexRub(int rubles) { + String str = String.valueOf(rubles); + str.substring(str.length() - 1); + return str; + } } \ No newline at end of file diff --git a/src/main/java/Product.java b/src/main/java/Product.java index 567538759..d5936d0ce 100644 --- a/src/main/java/Product.java +++ b/src/main/java/Product.java @@ -1,10 +1,8 @@ public class Product { String productName; - double productPrice; - public Product(String productName, double productPrice) { + public Product(String productName) { this.productName = productName; - this.productPrice = productPrice; } } From 7d125512e625e8036ab9b740a086a54cb7e659fd Mon Sep 17 00:00:00 2001 From: DexMP Date: 2023年10月25日 00:28:13 +0300 Subject: [PATCH 7/9] mini fix --- src/main/java/Calculator.java | 29 ----------------------------- 1 file changed, 29 deletions(-) delete mode 100644 src/main/java/Calculator.java diff --git a/src/main/java/Calculator.java b/src/main/java/Calculator.java deleted file mode 100644 index 9e88783ac..000000000 --- a/src/main/java/Calculator.java +++ /dev/null @@ -1,29 +0,0 @@ -public class Calculator { - - double summ; - int a; - int b; - - public Calculator(int a, int b) { - this.a = a; - this.b = b; - this.summ = sum(a, b); - } - - public static int sum(int a, int b) { - return a + b; - } - - public static int subtract(int a, int b) { - return a - b; - } - - public static int multiply(int a, int b) { - return a * b; - } - - public static int divide(int a, int b) { - return a / b; - } - -} From a7a368d5c58ecaa0213f69381cfc76a68b42ee87 Mon Sep 17 00:00:00 2001 From: DexMP <39278197+dexmp@users.noreply.github.com> Date: 2023年10月27日 20:14:07 +0300 Subject: [PATCH 8/9] Update src/main/java/Main.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Изменение ревьюера Co-authored-by: kgornostaeva <48408134+kgornostaeva@users.noreply.github.com> --- src/main/java/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 35ea48383..d86108abf 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -52,7 +52,7 @@ public static void main(String[] args) { System.out.println("Значение не может быть 0 или меньше!"); price = scanner_prices.nextDouble(); if (price> 0) { - System.out.println("Цена: " + String.format("%.2f", price)); + System.out.println(String.format("Цена: %.2f", price)); break; } } From 98508b07268703611c80f5b6a72c62f1fcb94339 Mon Sep 17 00:00:00 2001 From: DexMP <39278197+dexmp@users.noreply.github.com> Date: 2023年10月27日 20:14:55 +0300 Subject: [PATCH 9/9] Update src/main/java/Main.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Изменения ревьюера Co-authored-by: kgornostaeva <48408134+kgornostaeva@users.noreply.github.com> --- src/main/java/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index d86108abf..f401d5f78 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -58,7 +58,7 @@ public static void main(String[] args) { } summ += price; System.out.println("Добавленные товары:"); - for (int i = 0; i < productsName.size(); i++) { + for (Product name : productsName) { System.out.println("* " + productsName.get(i).productName); } System.out.println("Сумма: " + String.format("%.2f", summ));

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