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
tasha-a
wants to merge
2
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
2 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,101 @@ | ||
| import java.text.DecimalFormat; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| public static void calculator(int numberPeople) { | ||
|
|
||
| String finish = "Завершить"; | ||
| double sum = 00.00; | ||
| StringBuilder list = new StringBuilder(); | ||
| String endingRub = ""; | ||
| String endingSum = ""; | ||
|
|
||
| DecimalFormat decimalFormat = new DecimalFormat("#.##"); | ||
|
|
||
| while (true) { | ||
|
|
||
| System.out.println("Введите название товара или слово 'Завершить', чтобы получить результат"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| String nameGoods = scanner.nextLine(); | ||
|
|
||
| if (nameGoods.equalsIgnoreCase(finish)) { | ||
| break; | ||
| } | ||
|
|
||
| System.out.println("Введите стоимость в формате 00,00"); | ||
|
|
||
| if (scanner.hasNextDouble()) { | ||
|
|
||
| double price = scanner.nextDouble(); | ||
|
|
||
| if (price > 0) { | ||
| sum = sum + price; | ||
| endingRub = ending(price); | ||
| decimalFormat.format(price); | ||
|
|
||
| list.append(" \n" + nameGoods + " – " + price + " рубл" + endingRub); | ||
|
|
||
| } else { | ||
| System.out.println("Ошибка! Неверный формат цены. Попробуйте ввести данные о товаре снова"); | ||
| } | ||
| } else { | ||
| System.out.println("Ошибка! Неверный формат цены. Попробуйте ввести данные о товаре снова"); | ||
| } | ||
| } | ||
|
|
||
| endingSum = ending(sum / numberPeople); | ||
| System.out.println(list + "\n" + "С каждого: " + decimalFormat.format(sum / numberPeople) + " рубл" + endingSum); | ||
| } | ||
|
|
||
| public static String ending(double price) { | ||
|
|
||
| String endingOne = "ь"; | ||
| String endingTwo = "я"; | ||
| String endingThree = "ей"; | ||
| String ending; | ||
|
|
||
| int priceInt = (int) price; | ||
|
|
||
| if (price > 10) { | ||
| price %= 100; | ||
|
|
||
| if (price == 11 || price == 12 || price == 13 || price == 14) { | ||
| ending = endingThree; | ||
|
|
||
| } else { | ||
| priceInt %= 10; | ||
|
|
||
| switch (priceInt) { | ||
| case 1: | ||
| ending = endingOne; | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| ending = endingTwo; | ||
| break; | ||
| default: | ||
| ending = endingThree; | ||
| break; | ||
| } | ||
| } | ||
| } else { | ||
| priceInt %= 10; | ||
|
|
||
| switch (priceInt) { | ||
| case 1: | ||
| ending = endingOne; | ||
| break; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| ending = endingTwo; | ||
| break; | ||
| default: | ||
| ending = endingThree; | ||
| break; | ||
| } | ||
| } | ||
| return ending; | ||
| } | ||
| } | ||
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,30 @@ | ||
| import java.util.Scanner; | ||
| import java.text.DecimalFormat; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
|
|
||
| while (true) { | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На сколько человек делим счет?"); | ||
|
|
||
| if (scanner.hasNextInt()) { | ||
| int numberPeople = scanner.nextInt(); | ||
|
|
||
| if (numberPeople > 1) { | ||
| Calculator.calculator(numberPeople); | ||
| break; | ||
| } else { | ||
| System.out.println("Некорректное число. Попробуйте ввести количество людей снова"); | ||
| } | ||
| } else { | ||
| System.out.println("Некорректное число. Попробуйте ввести количество людей снова"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
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.
⏫ тут код по сути дублируется, поэтому можно не делать
if, а просто вынести и оставить только код, который в первой веткеЭтого должно хватить