forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
first try #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
Merged
first try #1
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
34e4b04
first version of program
Verionit c365cef
добавлены правильные окончания
Verionit 44b0b26
добавлена проверка на цифру в ввод соличества человек
Verionit 0d110f2
исправлены окончания слова рубль в выводе
Verionit 8fec438
fixed обработка некорректных значений цены
Verionit 6b45890
исправлены окÑончания в слове рубль
Verionit 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 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| class Calculator { | ||
| List<String> storage = new ArrayList<>(); | ||
| private int peopleCount; | ||
| private double moneySum; | ||
|
|
||
| public Calculator(int peopleCount) { | ||
| this.peopleCount = peopleCount; | ||
| } | ||
|
|
||
| public void addPrice(double singlePrice) { | ||
| moneySum += singlePrice; | ||
| } | ||
|
|
||
| public double getPersonalPrice() { | ||
| return moneySum / peopleCount; | ||
| } | ||
|
|
||
| public double getMoneySum() { | ||
| return moneySum; | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
src/main/java/DataOutput.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,20 @@ | ||
| public class DataOutput { | ||
| public static void showMessage(double personalPrice) { | ||
|
|
||
| String[] rightEndsForRuble = {"ля", "лей", "ль"}; | ||
|
|
||
| if ((int) personalPrice % 100 >= 10 && (int) personalPrice % 100 <= 20) { | ||
| System.out.printf("Каждый человек должен заплатить %.2f руб%s", | ||
| personalPrice, rightEndsForRuble[1]); | ||
| } else { | ||
| switch ((int) personalPrice % 10) { | ||
| case 1 -> System.out.printf("Каждый человек должен заплатить %.2f руб%s", | ||
| personalPrice, rightEndsForRuble[2]); | ||
| case 2, 3, 4 -> System.out.printf("Каждый человек должен заплатить %.2f руб%s", | ||
| personalPrice, rightEndsForRuble[0]); | ||
| default -> System.out.printf("Каждый человек должен заплатить %.2f руб%s", | ||
| personalPrice, rightEndsForRuble[1]); | ||
| } | ||
| } | ||
| } | ||
| } |
64 changes: 62 additions & 2 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,6 +1,66 @@ | ||
| import java.util.InputMismatchException; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
|
|
||
| Scanner sc = new Scanner(System.in); | ||
| String goodName; | ||
| int peopleCount; | ||
|
|
||
| System.out.println("Привет!\nНа скольких человек будем делить счёт?" + | ||
| " \n\uD83D\uDC49 введи значение: "); | ||
|
|
||
| while (true) { | ||
| try { | ||
| peopleCount = sc.nextInt(); | ||
| if (peopleCount > 1) break; | ||
|
|
||
| } catch (InputMismatchException e) { | ||
| System.out.println("Неверный формат ввода! Введите положительное число больше 1 "); | ||
| sc.nextLine(); | ||
| } | ||
| System.out.println("\uD83D\uDE20 Введите положительное число больше 1 "); | ||
| } | ||
|
|
||
| Calculator calculator = new Calculator(peopleCount); | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите название товара: "); | ||
| goodName = sc.next(); | ||
|
|
||
| if (goodName.equalsIgnoreCase("завершить")) { | ||
| break; | ||
| } | ||
|
|
||
| while (true) { | ||
| try { | ||
| System.out.println("Введите стоимость товара в формате XX.YY : "); | ||
| double newPrice = Double.parseDouble(sc.next()); | ||
| if (newPrice <= 0) { | ||
| System.out.println("Цена должна быть положительным числом!"); | ||
| } else { | ||
| calculator.addPrice(newPrice); | ||
| System.out.printf("Товар %s успешно добавлен\n", goodName); | ||
| System.out.println("Общая сумма на данный момент: " | ||
| + calculator.getMoneySum()); | ||
| break; | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("Цена должна быть положительным числом!"); | ||
| sc.nextLine(); | ||
| } | ||
| } | ||
| calculator.storage.add(goodName); | ||
| System.out.println("Вы хотите добавить ещё один товар? Если нет, введите - завершить"); | ||
| } | ||
|
|
||
| System.out.println("Добавленные товары: "); | ||
| for (String good : calculator.storage) { | ||
| System.out.println(" ** " + good + " ** "); | ||
| } | ||
|
|
||
| DataOutput finalOutput = new DataOutput(); | ||
| finalOutput.showMessage(calculator.getPersonalPrice()); | ||
| } | ||
| } | ||
| } |
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.