-
Notifications
You must be signed in to change notification settings - Fork 220
13.10.22 #73
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
Open
13.10.22 #73
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
3 changes: 3 additions & 0 deletions
.idea/.gitignore
Oops, something went wrong.
123 changes: 123 additions & 0 deletions
.idea/codeStyles/Project.xml
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
.idea/codeStyles/codeStyleConfig.xml
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
.idea/compiler.xml
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
.idea/git_toolbox_prj.xml
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
.idea/gradle.xml
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
.idea/misc.xml
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
.idea/vcs.xml
Oops, something went wrong.
85 changes: 80 additions & 5 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,83 @@ | ||
| public class Main { | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| private static final Scanner scan = new Scanner(System.in); | ||
| public static void main(String[] args) { | ||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| Calculator.inputPersons(); | ||
| Calculator.addProducts(); | ||
| Calculator.payPeople(); | ||
| } | ||
|
|
||
| public static class Calculator { | ||
| static double totalPrice = 0; | ||
| static String names = ""; | ||
| static int persons = 0; | ||
|
|
||
| public static void inputPersons() { | ||
| while (true) { | ||
| System.out.println("How many persons?"); | ||
| if (scan.hasNextInt()) { | ||
| persons = scan.nextInt(); | ||
| if (persons <= 1) { | ||
| System.out.println("Amount of persons must be integer > 1. Try again."); | ||
| continue; | ||
| } | ||
| break; | ||
| } else { | ||
| System.out.println("Amount of persons must be integer > 1. Try again."); | ||
| scan.nextLine(); | ||
| continue; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public static void addProducts() { | ||
| while (true) { | ||
| System.out.println("Product name: "); | ||
| String name = scan.next() + scan.nextLine(); | ||
| System.out.println("Price: "); | ||
| if (scan.hasNextDouble()) { | ||
| double price = scan.nextDouble(); | ||
| if (price < 0) { | ||
| System.out.println("Price must be positive double! Try again"); | ||
| continue; | ||
| } | ||
| totalPrice += price; | ||
| names += name + "\n"; | ||
| } else { | ||
| System.out.println("Price must be positive double! Try again"); | ||
| scan.nextLine(); | ||
| continue; | ||
| } | ||
| System.out.println("Product " + name + " successfully added! Enough? (yes - any symbol/no - n): "); | ||
| String answer = scan.next(); | ||
| if (answer.equalsIgnoreCase("n")) { | ||
| continue; | ||
| } else {break;} | ||
| } | ||
| } | ||
|
|
||
| public static void payPeople() { | ||
| int ruble = (int) Math.floor(totalPrice); | ||
| int payPeople = (int) Math.floor(totalPrice/persons); | ||
| System.out.println("Вы заказали следующие продукты:\n" + names + "на сумму: " + totalPrice + " " + Calculator.payPeoples(ruble)); | ||
| System.out.println("Каждый из " + persons + " человек заплатит по " + String.format("%.2f", totalPrice/persons) + " " + Calculator.payPeoples(payPeople)); | ||
| } | ||
|
|
||
| static String payPeoples(int ruble) { | ||
| if (ruble % 100 / 10 == 1) { | ||
| return "рублей"; | ||
| } else { | ||
| switch (ruble % 10) { | ||
| 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.