Repository navigation
Практикум. Sprint 2. Консольное приложение 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
darkelf007
wants to merge
13
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
13 commits
Select commit
Hold shift + click to select a range
b56bb66
First part of the task
darkelf007 4771204
Добавлена проверка наличия чисел, добавление товаров в калькулятор, у…
c9ace29
Добавлен класс
e035fac
Fix, add
35ef71c
add rubble
fb33c05
try ti funish the case
83fa32e
Fix errror
247be8b
fix error part 2
eb88d90
Update Main.java
darkelf007 24574ad
Update Main.java
darkelf007 718425f
Merge remote-tracking branch 'origin/dev' into dev
214c843
fix error 03.10.2023
4b4fa2c
fix error 08.10.2023
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 |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import java.util.ArrayList; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calculator { | ||
| public void calculator() { | ||
| double total = 0.0; | ||
| Scanner scanner = new Scanner(System.in); | ||
| String format = "%.2f"; | ||
|
|
||
| ArrayList<String> products = new ArrayList<>(); | ||
| ArrayList<Double> prices = new ArrayList<>(); | ||
|
|
||
| outerLoop: | ||
| while (true) { | ||
| System.out.println("Введите наименование товара (или 'Завершить' для завершения)"); | ||
|
|
||
| String name = scanner.nextLine().trim(); | ||
|
|
||
| if (name.equalsIgnoreCase("Завершить")) { | ||
| break; | ||
| } | ||
| products.add(name); | ||
|
|
||
| double priceNum; | ||
|
|
||
| while (true) { | ||
| System.out.println("Введите стоимость товара в формате руб.копейки"); | ||
|
|
||
| try { | ||
| String priceInput = scanner.nextLine().trim().replace(',', '.'); | ||
| priceNum = Double.parseDouble(priceInput); | ||
|
|
||
| if (priceNum <= 0) { | ||
| System.out.println("Введите положительное число"); | ||
| } else { | ||
| prices.add(priceNum); | ||
| break; | ||
| } | ||
| } catch (NumberFormatException e) { | ||
| System.out.println("\nОшибка: Введенный текст не является числом.\n"); | ||
| } | ||
| } | ||
|
|
||
| total += priceNum; | ||
|
|
||
| while (true) { | ||
| System.out.println("Хотите добавить еще одну позицию?\nВыберети вариант и наберите номер ответа.\n1. ДА\n2. НЕТ"); | ||
| String question = scanner.nextLine().trim(); | ||
|
|
||
| if (question.equalsIgnoreCase("1")) { | ||
| break; | ||
| } else if (question.equalsIgnoreCase("2")) { | ||
| break outerLoop; | ||
| } else { | ||
| System.out.println("\nНе верно. Введите только 1 или 2.\n"); | ||
| } | ||
| } | ||
| } | ||
| System.out.println("\nCписок продуктов:"); | ||
|
|
||
| for (int i=0; i<products.size(); i++){ | ||
| String product = products.get(i); | ||
| double priceСonversion = prices.get(i); | ||
|
|
||
| System.out.printf("Товар: " + product + " Стоимость %.2f " , priceСonversion ); | ||
| System.out.println(Ruble.getRuble(priceСonversion)); | ||
| } | ||
| System.out.print("\nОбщая стоимость всех товаров = " + String.format(format,total)); | ||
| System.out.println(" " + Ruble.getRuble(total) + "\n"); | ||
|
|
||
| Persons person = new Persons(); | ||
| double conversion = Double.parseDouble(person.countPersons()); | ||
| double division = total / conversion; | ||
|
|
||
| System.out.printf("Итого с каждого по: %.2f ", division); | ||
| System.out.println(Ruble.getRuble(division)); | ||
| } | ||
| } | ||
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,6 @@ | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("Hello world!"); | ||
| Calculator calc = new Calculator(); | ||
| calc.calculator(); | ||
| } | ||
| } |
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,28 @@ | ||
| import java.util.Scanner; | ||
|
|
||
| public class Persons { | ||
|
|
||
| public String countPersons() { | ||
| Scanner scanner = new Scanner(System.in); | ||
| System.out.println("Укажите на сколько человек разделить счет?"); | ||
| String persons; | ||
|
|
||
| while (true) { | ||
| persons = scanner.nextLine(); | ||
| try { | ||
| int number = Integer.parseInt(persons); | ||
| if (number <= 1) { | ||
| System.out.println("Некорректоное значение для подсчета"); | ||
| } else if (number > 1) { | ||
| break; | ||
| } | ||
| } | ||
| catch(NumberFormatException e){ | ||
| System.out.println("Ошибка: Введенный текст не является числом."); | ||
| } | ||
| } | ||
| System.out.println("Вы ввели " + persons); | ||
|
|
||
| return persons; | ||
| } | ||
| } |
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 @@ | ||
| public class Ruble { | ||
|
|
||
| public static String getRuble(double rubles) { | ||
| int count = (int) rubles % 100; | ||
| if (count > 4 && count < 21) | ||
| return "Рублей"; | ||
| switch (count % 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.
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.
Общепринято не оставлять так много пустых строк, это ухудшает восприятие. Золотой стандарт - 1 пустая строка, если надо отделить код