forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
консольное приложение №1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
void-85
wants to merge
5
commits into
main
Choose a base branch
from
dev
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| public class High_Load_Calculator | ||
| { | ||
| private int accounts = 0 ; | ||
| private double total_cost = 0.0 ; | ||
|
|
||
| private StringBuilder items = new StringBuilder(); | ||
|
|
||
| High_Load_Calculator( int n ){ accounts = n; } | ||
|
|
||
| public double add_item( String item, double cost ) | ||
| { | ||
| items.append(item).append("\n"); | ||
| total_cost += cost; | ||
|
|
||
| return total_cost; | ||
| } | ||
|
|
||
| public String get_items_string (){ return items.toString(); } | ||
| public double get_cost_per_account (){ return total_cost / accounts; } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,88 @@ | ||
| public class Main { | ||
| import java.util.Scanner; | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
|
|
||
|
|
||
| public class Main | ||
| { | ||
| 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 ; | ||
|
|
||
| private static final String EXIT_COMMAND = "Завершить"; | ||
| //static final String EXIT_COMMAND = "777"; | ||
|
|
||
| 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) | ||
| { | ||
| String s = ""; | ||
| System.out.println( ANSI_PURPLE+ "------------------------------------------------"); | ||
|
|
||
|
|
||
| while (!number_of_accounts_entered) { | ||
| System.out.println(ANSI_YELLOW + "На скольких человек необходимо разделить счёт?" + ANSI_BLUE); | ||
|
|
||
| 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 + "Ошибка! Вводите целое число больше единицы."); | ||
| } | ||
| } | ||
| 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) | ||
| 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.printf( "Каждый человек должен заплатить %.2f рубл", calculator.get_cost_per_account() ); | ||
|
|
||
| int n = (int) Math.floor( calculator.get_cost_per_account() ); | ||
|
|
||
| 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+ "------------------------------------------------"); | ||
| } | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.