forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
Pull request Ладика Олега по проектной работе №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
OLEG-LADIK
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
e6fb7da
Add dev branch
baae500
Коммит по проектной работе №1
OLEG-LADIK ed69cbf
Коммит 2 по проектной работе №1 (с исправлениями)
OLEG-LADIK 2a13e1a
Коммит 2 по проектной работе №1 (с исправлениями)
OLEG-LADIK f86e109
Коммит 2 по проектной работе №1 (с исправлениями)
OLEG-LADIK 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,16 @@ | ||
| import java.util.Scanner; | ||
| class Calculator { | ||
| void calculatingCheckPerGuest(double total, int numberOfGuests) { | ||
| double checkPerGuest = total / numberOfGuests; | ||
| double roundingCheck = Math.floor(checkPerGuest); | ||
| double roundingCheck2 = roundingCheck - Math.floor(roundingCheck / 100) * 100; | ||
| double roundingCheck3 = roundingCheck - Math.floor(roundingCheck / 10) * 10; | ||
| if(roundingCheck3 ==1&&roundingCheck2 !=11) { | ||
| System.out.println(String.format("Каждый гость должен заплатить %.2f рубль", checkPerGuest)); | ||
| } else if(roundingCheck3 >1&&roundingCheck3<5&roundingCheck2 !=12&roundingCheck2 !=13&roundingCheck2 !=14) { | ||
| System.out.println(String.format("Каждый гость должен заплатить %.2f рубля", checkPerGuest)); | ||
| } else { | ||
| System.out.println(String.format("Каждый гость должен заплатить %.2f рублей", checkPerGuest)); | ||
| } | ||
| } | ||
| } |
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,26 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| class Guests { | ||
| public static int gettingToKnowNumberOfGuests() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| int number = 0; | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите кол-во гостей, на которых нужно разделить счет"); | ||
| while (!scanner.hasNextInt()) { | ||
| System.out.println("Ошибка! Вы ввели текст! Вам нужно ввести целое число."); | ||
| scanner.next(); | ||
| } | ||
|
|
||
| number = scanner.nextInt(); | ||
| if (number > 1) { | ||
| break; | ||
| } else if (number < 0) { | ||
| System.out.println("Кол-во гостей не может быть отрицательынм"); | ||
| } else { | ||
| System.out.println("Кол-во гостей не может быть меньше 1"); | ||
| } | ||
| } | ||
| return number; | ||
| } | ||
| } |
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,21 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| // dev branch for Y.Practicum | ||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
|
|
||
| Guests guests = new Guests(); | ||
| int numberOfGuests = guests.gettingToKnowNumberOfGuests(); | ||
|
|
||
| Products products = new Products(); | ||
| double total = products.calculatingTotalExpense(); | ||
|
|
||
| Calculator calc = new Calculator(); | ||
| calc.calculatingCheckPerGuest(total,numberOfGuests); | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
|
|
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,54 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| class Products { | ||
|
|
||
| Scanner scan = new Scanner(System.in); | ||
| boolean ifWantFinish = true; | ||
| String[] dish = new String[100]; | ||
| int i =0; | ||
| double[] expense = new double[100]; | ||
| double price = 0; | ||
| double total = 0; | ||
| double calculatingTotalExpense() { | ||
| while (ifWantFinish) { | ||
| System.out.println("Введите название товара"); | ||
| dish[i] = scan.next(); | ||
|
|
||
| expense[i] = checkingIfValueIsNumber(); | ||
| total = total + expense[i]; | ||
|
|
||
| System.out.println("Товар " + dish[i] + " стоимостью " + expense[i] + " руб. успешно добавлен!"); | ||
| i++; | ||
| System.out.println("\nВы хотите ввести еще товары? Если да, то введите любой текст. Если нет, введите 'Завершить'"); | ||
| ifWantFinish = !scan.next().equalsIgnoreCase("Завершить"); | ||
| } | ||
| System.out.println("Добавленные товары:"); | ||
| for (int l = 0; l < i; l++) { | ||
| System.out.println((l + 1) + ". " + dish[l] + " Цена " + expense[l] + " руб."); | ||
| } | ||
| return total; | ||
| } | ||
|
|
||
| double checkingIfValueIsNumber () { | ||
| while(true) { | ||
| System.out.println("Введите цену товара в формате рубли,копейки"); | ||
| while (true) { | ||
| if (scan.hasNextDouble()) { | ||
| break; | ||
| } else { | ||
| System.out.println("Ошибка! Введите число!"); | ||
| scan.next(); | ||
| } | ||
| } | ||
| price = scan.nextDouble(); | ||
| if (price <= 0) { | ||
| System.out.println("Цена блюда не может быть отрицательной и не может быть равна нулю"); | ||
| } else { | ||
| break; | ||
| } | ||
| } | ||
| return price; | ||
| } | ||
|
|
||
|
|
||
| } | ||
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.
⚠ Также лучше добавить проверку, что стоимость товара не может быть отрицательной - в прошлой итерации я об этом упомянул в PR. Если ввести -1, то программа продолжит работу и выведет в консоль добавленный товар с стоимостью -1.0 руб, что лучше поправить