-
Notifications
You must be signed in to change notification settings - Fork 965
Сдача Проектной Работы No 1 - 2 Попытка) #43
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6fb7da
Add dev branch
797f29a
Merge pull request #1 from BOGDAN1986/dev
BOGDAN1986 f80bfd1
Merge pull request #2 from BOGDAN1986/main
BOGDAN1986 2fbcaba
Сдаю на проверку первый проект! No1
BOGDAN1986 cd50b1c
Merge remote-tracking branch 'origin/dev' into dev
BOGDAN1986 addb6b4
Сдача Проектной Работы No 1 - 3 Попытка)
BOGDAN1986 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
18 changes: 18 additions & 0 deletions
src/main/java/GetRubleAddition.java
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,18 @@ | ||
| class Rubles { | ||
| public static String GetRubleAddition(int num) { | ||
| int preLastDigit = num % 100 / 10; | ||
| if (preLastDigit == 1) { | ||
| return "рублей"; | ||
| } | ||
| switch (num % 10) { | ||
| case 1: | ||
| return "рубль"; | ||
| case 2: | ||
| case 3: | ||
| case 4: | ||
| return "рубля"; | ||
| default: | ||
| return "рублей"; | ||
| } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
src/main/java/GroceryList.java
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,36 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| class GroceryList { | ||
|
|
||
| public static double Product(Scanner nameProduct) { | ||
|
|
||
| double sum = 0.0; | ||
| StringBuilder products = new StringBuilder(("Добавить блюда")); //Обьявить блюда | ||
|
|
||
| while (true) { | ||
| String name; | ||
| System.out.println("Введите название блюда. Либо напишите 'Завершить'."); // Ввести название блюда | ||
| name = nameProduct.next(); | ||
|
|
||
| if (name.equalsIgnoreCase("Завершить")) { //Подсчет итога | ||
| System.out.println(products); | ||
| break; | ||
| } | ||
|
|
||
| double price; | ||
| System.out.println("Введите стоимость блюда"); // Ввести стоимость | ||
| while (!nameProduct.hasNextDouble()) { | ||
| System.out.println("Введите стоимость блюда в формате: 11,11"); | ||
| nameProduct.next(); | ||
| } | ||
| price = nameProduct.nextDouble(); | ||
|
|
||
| if (price > 0) { | ||
| products.append("\n").append(name).append(" по цене ").append(price); | ||
| sum += price; | ||
| System.out.println("Блюдо добавлено"); | ||
| } | ||
| } | ||
| return sum; | ||
| } | ||
| } |
30 changes: 26 additions & 4 deletions
src/main/java/Main.java
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,30 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("На сколько персон разделить счет?"); //Количество людей | ||
|
|
||
| while (true) { | ||
| if (!scanner.hasNextInt()) { | ||
| System.out.println("Введите целое число."); | ||
| scanner.next(); | ||
| } | ||
| int people = scanner.nextInt(); | ||
| if (people == 1) { | ||
| System.out.println("Хотите разделить свою еду?\nДобавьте больше людей!"); | ||
| } | ||
| if (people < 1) { | ||
| System.out.println("Неправильное количество!\nВведите положительное целое число!"); | ||
| } | ||
| if (people > 1) { | ||
| System.out.println("Давайте подсчитаем!"); | ||
| Double value = GroceryList.Product(scanner) / people; | ||
| String result = String.format("%.2f", value); | ||
| System.out.println("Сумма с человека: " + result + " " + Rubles.GetRubleAddition((int) Math.floor(value))); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
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.