-
Notifications
You must be signed in to change notification settings - Fork 220
Финальный вариант работы #148
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
7 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
24 changes: 24 additions & 0 deletions
src/main/java/Calculator.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,24 @@ | ||
|
|
||
| class Calculator { | ||
|
|
||
|
|
||
| static String cart = "Добавленные товары "; | ||
| double totalPrice = 0; | ||
| double devideSum; | ||
| int numberPeople; | ||
|
|
||
| void calcul(added added) { | ||
| totalPrice = totalPrice + added.prise; | ||
| cart = cart + "\n" + added.product; | ||
| System.out.println(added.product + " - в корзине"); | ||
| devideSum = totalPrice / numberPeople; | ||
|
|
||
| } | ||
|
|
||
| Calculator(int numberPeople) { | ||
| this.numberPeople = numberPeople; | ||
| } | ||
| } | ||
| // | ||
|
|
||
|
|
57 changes: 54 additions & 3 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,59 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| int numberPeople; | ||
|
|
||
| while (true) { | ||
|
|
||
| System.out.println("На скольких человек необходимо разделить счёт"); | ||
| numberPeople = scanner.nextInt(); | ||
| if (numberPeople > 1) { | ||
| break; | ||
| } else if (numberPeople <= 1) { | ||
| System.out.println("Это некорректное значение для подсчёта, повторите ввод"); | ||
| } | ||
| } | ||
| System.out.println("Сейчас все сделаем"); | ||
|
|
||
|
|
||
| Calculator Calculator = new Calculator(numberPeople); | ||
| double prise; | ||
| while (true) { | ||
| System.out.println("Введите название продукта"); | ||
| String product = scanner.next(); | ||
| try { | ||
| System.out.println("Введите стоимость в формате: 'рубли.копейки' 10.45, 11.40"); | ||
| prise = scanner.nextDouble(); | ||
|
|
||
| Calculator.calcul(new added(product, prise)); | ||
| System.out.println("Хотите добавить ещё один товар? Введите команду завершить, для прекращения ввода. Для продлежния введите любое слово или символ"); | ||
| String answer = scanner.next(); | ||
| if (answer.equalsIgnoreCase("Завершить")) { | ||
| break; | ||
| } | ||
| } catch(Exception e) { | ||
| System.out.println(e.getMessage()); | ||
| } | ||
| } | ||
|
|
||
| rubleOptions RubleOptions = new rubleOptions(); | ||
| double value = Calculator.devideSum; | ||
| String result = String.format("%.2f",value); | ||
| System.out.println(Calculator.cart + "\n" + "К оплате с человека " + result + RubleOptions.rubles(value)); | ||
| } | ||
| } | ||
| // Привет, не могу исправить заглавную букву класса, выдает ошибку. Такое ощущение, что андроид студио логает. | ||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
| // ваш код начнется здесь | ||
| // вы не должны ограничиваться только классом Main и можете создавать свои классы по необходимости | ||
| System.out.println("Привет Мир"); | ||
| } | ||
| } | ||
|
|
||
|
|
12 changes: 12 additions & 0 deletions
src/main/java/added.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,12 @@ | ||
| class added { | ||
|
|
||
| String product; | ||
| double prise; | ||
|
|
||
| added(String product,double prise) { | ||
| this.product = product; | ||
| this.prise = prise; | ||
| } | ||
|
|
||
| } | ||
| // |
23 changes: 23 additions & 0 deletions
src/main/java/rubleOptions.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,23 @@ | ||
| public class rubleOptions { | ||
|
|
||
|
|
||
| String rubles(double value) { | ||
| double rubles = Math.floor(value); | ||
| if (rubles == 1) { | ||
| return " рубль"; | ||
| } else if (rubles %100 == 11 || rubles%100 == 12 || rubles%100 == 13 || rubles%100 == 14) { | ||
1sleepwalker1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return " рублей"; | ||
| } else if (rubles % 10 == 1) { | ||
| return " рубль"; | ||
| } else if (rubles % 10 >= 2 && rubles % 10 <= 4) { | ||
| return " рубля"; | ||
| } else { | ||
| 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.