From e6fb7daceadc7370de98eb7fa7a7a3c5e7552c3c Mon Sep 17 00:00:00 2001 From: s-buvaka Date: Wed, 30 Nov 2022 22:20:36 +0300 Subject: [PATCH 1/5] Add dev branch --- src/main/java/Main.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index a9198c435..955424e69 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,3 +1,4 @@ +// dev branch for Y.Practicum public class Main { public static void main(String[] args) { From e6e6fce352f70c3c54aeaf37a134ee135a1b3123 Mon Sep 17 00:00:00 2001 From: void-85 Date: Sun, 5 Feb 2023 19:50:36 +0500 Subject: [PATCH 2/5] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 + src/main/java/High_Load_Calculator.java | 24 +++++ src/main/java/Main.java | 120 ++++++++++++++++++++++-- 3 files changed, 140 insertions(+), 6 deletions(-) create mode 100644 src/main/java/High_Load_Calculator.java diff --git a/gradle.properties b/gradle.properties index 3c7a8bd3a..6b137ad6d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -21,3 +21,5 @@ kotlin.code.style=official # resources declared in the library itself and none from the library's dependencies, # thereby reducing the size of the R class for that library android.nonTransitiveRClass=true + +org.gradle.warning.mode=none diff --git a/src/main/java/High_Load_Calculator.java b/src/main/java/High_Load_Calculator.java new file mode 100644 index 000000000..3fc6cf746 --- /dev/null +++ b/src/main/java/High_Load_Calculator.java @@ -0,0 +1,24 @@ +public class High_Load_Calculator +{ + + private Integer accounts = 0 ; + private Double total_cost = 0.0 ; + private String items = "" ; + + + + High_Load_Calculator( Integer n ){ accounts = n; } + + + + public Double add_item( String item, Double cost ) + { + items += item + "\n" ; + total_cost += cost ; + + return total_cost; + } + + public String get_items_string (){ return items; } + public Double get_cost_per_account (){ return total_cost / accounts; } +} diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 955424e69..027dbdf3f 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,9 +1,117 @@ -// dev branch for Y.Practicum -public class Main { +import java.util.Scanner; - public static void main(String[] args) { - // ваш код начнется здесь - // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости - System.out.println("Привет Мир"); + +public class Main +{ + static Scanner input = new Scanner( System.in ); + + + + static Boolean number_of_accounts_entered = false ; + static Boolean items_entered = false ; + static Integer number_of_accounts = 0 ; + + + static final String EXIT_COMMAND = "Завершить"; + //static final String EXIT_COMMAND = "777"; + + static final String ANSI_RESET = "\u001B[0m"; + static final String ANSI_BLACK = "\u001B[30m"; + static final String ANSI_RED = "\u001B[31m"; + static final String ANSI_GREEN = "\u001B[32m"; + static final String ANSI_YELLOW = "\u001B[33m"; + static final String ANSI_BLUE = "\u001B[34m"; + static final String ANSI_PURPLE = "\u001B[35m"; + static final String ANSI_CYAN = "\u001B[36m"; + static final String ANSI_WHITE = "\u001B[37m"; + + + + + public static void main(String[] args) + { + String s = ""; + System.out.println( ANSI_PURPLE+ "------------------------------------------------"); + + + while ( !number_of_accounts_entered ) + { + System.out.println(ANSI_YELLOW + "На скольких человек необходимо разделить счёт?" + ANSI_BLUE); + + // допустимые входные значения ==[2;999] + s = input.nextLine(); if( s.matches("\\d{1,3}") ) + if( Integer.parseInt( s ) > 1 ) + { number_of_accounts_entered =true; } + + if( !number_of_accounts_entered ) + { System.out.println( ANSI_RED+ "Ошибка! Вводите целое число больше единицы." ); } + } + number_of_accounts = Integer.parseInt(s); + High_Load_Calculator calculator = new High_Load_Calculator( number_of_accounts ); + + + while ( !items_entered ) + { + System.out.println(ANSI_YELLOW+ "\nВведите название товара и его стоимость в формате \""+ + ANSI_GREEN+ "Товар = Стоимость"+ + ANSI_YELLOW+ "\" или \""+ + ANSI_GREEN+ EXIT_COMMAND + + ANSI_YELLOW+ "\" для расчёта"); + + s = input.nextLine(); if( s.equalsIgnoreCase(EXIT_COMMAND) ) items_entered = true; + else if( s.contains("=")) + { + String[] array_of_s = s.split("="); + if( array_of_s.length == 2 ) + if( array_of_s[0].length()>0 && array_of_s[1].length()>0 ) + { + array_of_s[0] = array_of_s[0].trim(); + + System.out.println( String.format( + ANSI_BLUE+ "товар \"%s\" добавлен ( итого: %.2f руб.)", + array_of_s[0], + + calculator.add_item( array_of_s[0], Double.parseDouble(array_of_s[1]) ))); + } + } + } + + System.out.println( ANSI_CYAN+ "\nДобавленные товары:\n"+ + calculator.get_items_string()); + + System.out.print( String.format( "Каждый человек должен заплатить %.2f рубл", calculator.get_cost_per_account() )); + + Double d = Math.floor( calculator.get_cost_per_account() ); + Integer n = d.intValue(); + if( 5 <= n && n <= 20 ) System.out.println("ей"); else + if( n%10 == 1 ) System.out.println("ь" ); else + if( 2 <= n%10 && n%10 <= 4 ) System.out.println("я" ); else + System.out.println("ей"); + + System.out.println( ANSI_PURPLE+ "------------------------------------------------"); } } + + + + + + + + + + + + + + + + + + + + + + + + From 033b1b956d6ca8aaf84c1ff32a44393452a61aae Mon Sep 17 00:00:00 2001 From: void-85 Date: Sun, 5 Feb 2023 20:12:01 +0500 Subject: [PATCH 3/5] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 027dbdf3f..f7404cb1c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -64,14 +64,21 @@ else if( s.contains("=")) String[] array_of_s = s.split("="); if( array_of_s.length == 2 ) if( array_of_s[0].length()>0 && array_of_s[1].length()>0 ) + try { + Double d = Double.parseDouble(array_of_s[1]); + array_of_s[0] = array_of_s[0].trim(); System.out.println( String.format( ANSI_BLUE+ "товар \"%s\" добавлен ( итого: %.2f руб.)", array_of_s[0], - calculator.add_item( array_of_s[0], Double.parseDouble(array_of_s[1]) ))); + calculator.add_item( array_of_s[0], d ))); + } + catch( NumberFormatException e ) + { + System.out.println( ANSI_RED+ "Ошибка в стоимости товара!" ); } } } From a887dc75b60925e85fb133549a53fc26c5bf62ba Mon Sep 17 00:00:00 2001 From: void-85 Date: Sun, 5 Feb 2023 20:44:15 +0500 Subject: [PATCH 4/5] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/Main.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/Main.java b/src/main/java/Main.java index f7404cb1c..559bb6dd2 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -90,10 +90,10 @@ else if( s.contains("=")) Double d = Math.floor( calculator.get_cost_per_account() ); Integer n = d.intValue(); - if( 5 <= n && n <= 20 ) System.out.println("ей"); else - if( n%10 == 1 ) System.out.println("ь" ); else - if( 2 <= n%10 && n%10 <= 4 ) System.out.println("я" ); else - System.out.println("ей"); + if( 5 <= n%100 && n%100 <= 20 ) System.out.println("ей"); else + if( n%10 == 1 ) System.out.println("ь" ); else + if( 2 <= n%10 && n%10 <= 4 ) System.out.println("я" ); else + System.out.println("ей"); System.out.println( ANSI_PURPLE+ "------------------------------------------------"); } From 3fd2be7e6ae129a61891555348f3f3f4b65a73b2 Mon Sep 17 00:00:00 2001 From: void-85 Date: Sun, 5 Feb 2023 22:25:41 +0500 Subject: [PATCH 5/5] =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D0=BE=D0=BB=D1=8C?= =?UTF-8?q?=D0=BD=D0=BE=D0=B5=20=D0=BF=D1=80=D0=B8=D0=BB=D0=BE=D0=B6=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/High_Load_Calculator.java | 22 ++-- src/main/java/Main.java | 140 +++++++++--------------- 2 files changed, 61 insertions(+), 101 deletions(-) diff --git a/src/main/java/High_Load_Calculator.java b/src/main/java/High_Load_Calculator.java index 3fc6cf746..c9967f404 100644 --- a/src/main/java/High_Load_Calculator.java +++ b/src/main/java/High_Load_Calculator.java @@ -1,24 +1,20 @@ public class High_Load_Calculator { + private int accounts = 0 ; + private double total_cost = 0.0 ; - private Integer accounts = 0 ; - private Double total_cost = 0.0 ; - private String items = "" ; + private StringBuilder items = new StringBuilder(); + High_Load_Calculator( int n ){ accounts = n; } - - High_Load_Calculator( Integer n ){ accounts = n; } - - - - public Double add_item( String item, Double cost ) + public double add_item( String item, double cost ) { - items += item + "\n" ; - total_cost += cost ; + items.append(item).append("\n"); + total_cost += cost; return total_cost; } - public String get_items_string (){ return items; } - public Double get_cost_per_account (){ return total_cost / accounts; } + public String get_items_string (){ return items.toString(); } + public double get_cost_per_account (){ return total_cost / accounts; } } diff --git a/src/main/java/Main.java b/src/main/java/Main.java index 559bb6dd2..ff00a244c 100644 --- a/src/main/java/Main.java +++ b/src/main/java/Main.java @@ -1,32 +1,24 @@ import java.util.Scanner; + public class Main { - static Scanner input = new Scanner( System.in ); - - - - static Boolean number_of_accounts_entered = false ; - static Boolean items_entered = false ; - static Integer number_of_accounts = 0 ; + private static Scanner input = new Scanner( System.in ); + private static boolean number_of_accounts_entered = false ; + private static boolean items_entered = false ; + private static int number_of_accounts = 0 ; - static final String EXIT_COMMAND = "Завершить"; + private static final String EXIT_COMMAND = "Завершить"; //static final String EXIT_COMMAND = "777"; - static final String ANSI_RESET = "\u001B[0m"; - static final String ANSI_BLACK = "\u001B[30m"; - static final String ANSI_RED = "\u001B[31m"; - static final String ANSI_GREEN = "\u001B[32m"; - static final String ANSI_YELLOW = "\u001B[33m"; - static final String ANSI_BLUE = "\u001B[34m"; - static final String ANSI_PURPLE = "\u001B[35m"; - static final String ANSI_CYAN = "\u001B[36m"; - static final String ANSI_WHITE = "\u001B[37m"; - - - + private static final String ANSI_RED = "\u001B[31m" ; + private static final String ANSI_GREEN = "\u001B[32m" ; + private static final String ANSI_YELLOW = "\u001B[33m" ; + private static final String ANSI_BLUE = "\u001B[34m" ; + private static final String ANSI_PURPLE = "\u001B[35m" ; + private static final String ANSI_CYAN = "\u001B[36m" ; public static void main(String[] args) { @@ -34,62 +26,58 @@ public static void main(String[] args) System.out.println( ANSI_PURPLE+ "------------------------------------------------"); - while ( !number_of_accounts_entered ) - { + while (!number_of_accounts_entered) { System.out.println(ANSI_YELLOW + "На скольких человек необходимо разделить счёт?" + ANSI_BLUE); - // допустимые входные значения ==[2;999] - s = input.nextLine(); if( s.matches("\\d{1,3}") ) - if( Integer.parseInt( s ) > 1 ) - { number_of_accounts_entered =true; } + s = input.nextLine(); + if (s.matches("\\d{1,9}")) if (Integer.parseInt(s) > 1) { + number_of_accounts_entered = true; + } - if( !number_of_accounts_entered ) - { System.out.println( ANSI_RED+ "Ошибка! Вводите целое число больше единицы." ); } + if (!number_of_accounts_entered) { + System.out.println(ANSI_RED + "Ошибка! Вводите целое число больше единицы."); + } } number_of_accounts = Integer.parseInt(s); - High_Load_Calculator calculator = new High_Load_Calculator( number_of_accounts ); + High_Load_Calculator calculator = new High_Load_Calculator(number_of_accounts); while ( !items_entered ) { - System.out.println(ANSI_YELLOW+ "\nВведите название товара и его стоимость в формате \""+ - ANSI_GREEN+ "Товар = Стоимость"+ - ANSI_YELLOW+ "\" или \""+ - ANSI_GREEN+ EXIT_COMMAND + - ANSI_YELLOW+ "\" для расчёта"); - - s = input.nextLine(); if( s.equalsIgnoreCase(EXIT_COMMAND) ) items_entered = true; - else if( s.contains("=")) - { - String[] array_of_s = s.split("="); - if( array_of_s.length == 2 ) - if( array_of_s[0].length()>0 && array_of_s[1].length()>0 ) - try - { - Double d = Double.parseDouble(array_of_s[1]); - - array_of_s[0] = array_of_s[0].trim(); - - System.out.println( String.format( - ANSI_BLUE+ "товар \"%s\" добавлен ( итого: %.2f руб.)", - array_of_s[0], - - calculator.add_item( array_of_s[0], d ))); - } - catch( NumberFormatException e ) - { - System.out.println( ANSI_RED+ "Ошибка в стоимости товара!" ); - } - } + System.out.println(ANSI_YELLOW + "\nВведите название товара и его стоимость в формате \""+ + ANSI_GREEN + "Товар = Стоимость"+ + ANSI_YELLOW + "\" или \""+ + ANSI_GREEN + EXIT_COMMAND + + ANSI_YELLOW + "\" для расчёта"); + + s = input.nextLine(); + if (s.equalsIgnoreCase(EXIT_COMMAND)) items_entered = true; + else if (s.contains("=")) { + String[] array_of_s = s.split("="); + if (array_of_s.length == 2) + if (array_of_s[0].length() > 0 && array_of_s[1].length() > 0) + try { + double d = Double.parseDouble(array_of_s[1]); + + if (d <= 0) System.out.println(ANSI_RED + "Отрицательное значение в стоимости товара!"); + else { + array_of_s[0] = array_of_s[0].trim(); + double total_cost = calculator.add_item(array_of_s[0], d); + + System.out.printf(ANSI_BLUE + "товар \"%s\" добавлен ( итого: %.2f руб.)%n\n", + array_of_s[0], total_cost); + } + } catch (NumberFormatException e) { + System.out.println(ANSI_RED + "Ошибка в стоимости товара!"); + } + } } - System.out.println( ANSI_CYAN+ "\nДобавленные товары:\n"+ - calculator.get_items_string()); + System.out.println( ANSI_CYAN+ "\nДобавленные товары:\n"+ calculator.get_items_string()); + System.out.printf( "Каждый человек должен заплатить %.2f рубл", calculator.get_cost_per_account() ); - System.out.print( String.format( "Каждый человек должен заплатить %.2f рубл", calculator.get_cost_per_account() )); + int n = (int) Math.floor( calculator.get_cost_per_account() ); - Double d = Math.floor( calculator.get_cost_per_account() ); - Integer n = d.intValue(); if( 5 <= n%100 && n%100 <= 20 ) System.out.println("ей"); else if( n%10 == 1 ) System.out.println("ь" ); else if( 2 <= n%10 && n%10 <= 4 ) System.out.println("я" ); else @@ -97,28 +85,4 @@ else if( s.contains("=")) System.out.println( ANSI_PURPLE+ "------------------------------------------------"); } -} - - - - - - - - - - - - - - - - - - - - - - - - +} \ No newline at end of file