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
mizyakov-ivan
wants to merge
3
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
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| static Scanner scanner = new Scanner(System.in); | ||
|
|
||
| public static void calculator() { | ||
| System.out.println("Введите название товара"); | ||
| String nameProduct = scanner.next(); | ||
| Main.amountProducts = Main.amountProducts + 1; | ||
| Main.listProducts = Main.listProducts + "\n" + nameProduct; | ||
| System.out.println("Введите стоимость товара в формате в рубли и копейки. Образец 11.11"); | ||
| double price = scanner.nextDouble(); | ||
| while (price < 0) { | ||
| System.out.println("Ошибка! У товара не может быть отрицательной стоимости. Повторите ввод цены."); | ||
| price = scanner.nextDouble(); | ||
| } | ||
| Main.totalPrice = Main.totalPrice + price; | ||
| System.out.println("Товар добавлен.\nДля продолжения введите любой символ и нажмите Enter. " + | ||
| "\nЕсли хотите завершить процесс добавления товара введите 'Завершить'"); | ||
| String input = scanner.next(); | ||
| if (!input.equalsIgnoreCase("завершить")){ | ||
| calculator(); | ||
| } | ||
| } | ||
| } |
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,6 +1,32 @@ | ||
|
|
||
| import java.util.Scanner; | ||
| import java.util.InputMismatchException; | ||
| public class Main { | ||
| static int amountPeople=0; // количество людей | ||
| static double totalPrice = 0; // итоговая стоимость товаров | ||
| static int amountProducts= 0; // количество товаров | ||
| static String listProducts = ""; // список товаров | ||
| static Scanner scanner = new Scanner(System.in); | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
|
|
||
| while (amountPeople <= 1) { | ||
| try { | ||
| System.out.println("Введите количество человек:"); | ||
| amountPeople = scanner.nextInt(); | ||
|
|
||
| if (amountPeople == 1) { | ||
| System.out.println("Нет смысла делить счет, укажите другое значение."); | ||
| } else if (amountPeople < 1) { | ||
| System.out.println("Ошибка: некорректное значение для подсчёта."); | ||
| } | ||
| } catch (InputMismatchException e) { | ||
| System.out.println("Ошибка: некорректный формат ввода. Введите целое число."); | ||
| scanner.nextLine(); | ||
| } | ||
| } | ||
| Calculator.calculator(); | ||
| System.out.printf("Сумма которую необходимо поделить равна: %.2f\n", totalPrice); | ||
| System.out.println("Количество человек: " + amountPeople + "\n" + "Количество добавленных товаров: "+ | ||
| amountProducts + "\n" + "Добавленные товары:" + listProducts); | ||
| SplitCheck.formatter(); | ||
| } | ||
| } | ||
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,28 @@ | ||
| public class SplitCheck { | ||
| public static void formatter(){ | ||
| double split = Main.totalPrice / Main.amountPeople; | ||
| String format = "Каждый человек должен заплатить поровну, а именно: %.2f %s"; | ||
| int roundedSplit = (int)Math.floor(split); | ||
| int preLastDigit = roundedSplit % 100 / 10; | ||
| int lastDigit = roundedSplit % 10; | ||
| if (preLastDigit == 1){ | ||
| String rubles = "рублей"; | ||
| System.out.println(String.format(format, split, rubles)); | ||
| } else { | ||
| String rubles; | ||
| switch (lastDigit) { | ||
| case 1: | ||
| rubles = "рубль"; | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| rubles = "рубля"; | ||
| break; | ||
| default: | ||
| rubles = "рублей"; | ||
| break; | ||
| }System.out.println(String.format(format, split, rubles)); | ||
| } | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Я бы не стал делать программу на статиках. В разработке под андроид используется преимущественно ООП, так что лучше сразу делать таким образом, создавая объекты вручную