Repository navigation
Проектная работа №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
VeronikaZueva
wants to merge
10
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
10 commits
Select commit
Hold shift + click to select a range
e80d7fe
Stage 1. Process of add count Person
VeronikaZueva 283c3f7
Stage 1. Process of add count Person
VeronikaZueva 5ea46c8
Stage 1. Process of add count Person
VeronikaZueva cfa5ea5
Stage 1. Process of add count Person
VeronikaZueva 0cbde3f
Stage 2. Process of add dish
VeronikaZueva afa955a
Stage 3. Process of add dish - ready.
VeronikaZueva 49fa944
Stage 4. Add dishes and prices.
VeronikaZueva d323212
Stage 5. Add Calculate and Final Screen.
VeronikaZueva 7db74b2
Final Version
VeronikaZueva 9a96433
Final Version
VeronikaZueva 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 |
|---|---|---|
| @@ -1,6 +1,102 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
|
|
||
| Scanner scanner = new Scanner(System.in); | ||
| scanner.useDelimiter("\\n"); | ||
| StringBuilder menu = new StringBuilder(); | ||
|
|
||
| System.out.println("На сколько человек разделить ваш счет?"); | ||
| int friends = countFriend(scanner); | ||
| int processAdd; | ||
| double total = 0; | ||
| do { | ||
| System.out.println("Укажите название блюда:"); | ||
| String dish = scanner.next(); | ||
| while(dish.isEmpty()) { | ||
| System.out.println("Название блюда не должно быть пустым."); | ||
| dish = scanner.next(); | ||
| } | ||
| menu.append(dish).append("\n"); | ||
|
|
||
| System.out.println("Укажите стоимость блюда:"); | ||
| total = total + checkPrice(scanner); | ||
|
|
||
|
|
||
| System.out.println("Блюдо добавлено в список"); | ||
|
|
||
|
|
||
| System.out.println("Желаете добавить еще одно блюдо? (Укажите \"Завершить\" для завершения процесса или введите любые символы, для продолжения)"); | ||
| processAdd = enterCommand(scanner); | ||
| } while(processAdd == 0); | ||
|
|
||
| //Выводим калькулятор | ||
| double calculate = total / (double)friends; | ||
| String bill = String.format("%.2f", calculate); | ||
| String sum = String.format("%.2f", total); | ||
|
|
||
| Ruble rubleSum = new Ruble(); | ||
| Ruble rubleBill = new Ruble(); | ||
| String changeRubleSum = rubleSum.recieveRuble(total); | ||
| String changeRubleBill = rubleBill.recieveRuble(calculate); | ||
|
|
||
| String resultMenu = menu.toString(); | ||
| System.out.println("Добавленные блюда:"); | ||
| System.out.println(resultMenu); | ||
| System.out.println("Стоимость заказа:"); | ||
| System.out.println(sum + changeRubleSum); | ||
| System.out.println("Количество гостей:"); | ||
| System.out.println(friends); | ||
| System.out.println("Стоимость чека на каждого:"); | ||
| System.out.println(bill + changeRubleBill); | ||
|
|
||
| } | ||
|
|
||
| //Обрабатываем вывод количества друзей | ||
| public static int countFriend(Scanner scanner) { | ||
| while (true) { | ||
| if(scanner.hasNextInt()) { | ||
| int number = scanner.nextInt(); | ||
| if(number <= 1) {System.out.println("Укажите число больше 1.");} | ||
| else {return number;} | ||
|
|
||
| } else { | ||
| System.out.println("Необходимо указать целое число."); | ||
| scanner.next(); | ||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
| //Обрабатываем вывод суммы | ||
| public static double checkPrice (Scanner scanner) { | ||
| while (true) { | ||
| if(scanner.hasNextDouble()) { | ||
| double price = scanner.nextDouble(); | ||
| if(price <= 0) {System.out.println("Укажите число больше 0.");} | ||
| else {return price;} | ||
|
|
||
| } else { | ||
| System.out.println("Необходимо указать число."); | ||
| scanner.next(); | ||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
| //Решаем, завершать ли нам добавление блюд или продолжать | ||
| public static int enterCommand(Scanner scanner) { | ||
| String dishAdd = scanner.next(); | ||
| int command; | ||
| if(dishAdd.equalsIgnoreCase("Завершить")) { | ||
| command = 1; | ||
| } else { | ||
| command = 0; | ||
| } | ||
| return command; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
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,24 @@ | ||
| public class Ruble { | ||
|
|
||
| public String recieveRuble(double rublePrice) { | ||
| int resultPrice = (int)Math.floor(rublePrice); | ||
|
|
||
| if(resultPrice >= 11 && resultPrice <= 19) { | ||
| return " рублей"; | ||
| } | ||
| else { | ||
| int lastNumber = resultPrice % 10; | ||
| switch(lastNumber) { | ||
| case 1 : | ||
| return " рубль"; | ||
| case 2 : | ||
| case 3 : | ||
| case 4 : | ||
| return " рубля"; | ||
| default : | ||
| return " рублей"; | ||
|
|
||
| } | ||
| } | ||
| } | ||
| } |
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 if else else - нужно избавиться от такой вложенности