forked from Yandex-Practicum/Java-Module-Project-YP
-
Notifications
You must be signed in to change notification settings - Fork 0
PR#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
gen530ts
wants to merge
15
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
PR#1 #1
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
47b5837
Init commit
39b1bc7
Working in try_catch
f5b7055
MainCalc_hasNextInt
96990ea
MainCalc_hasNextInt
df90552
Merge remote-tracking branch 'origin/dev' into dev
cadb51b
Merge remote-tracking branch 'origin/dev' into dev
371dc15
Merge remote-tracking branch 'origin/dev' into dev
2057748
working without try_catch
5898941
working without try_catch
1ef9f4b
Merge remote-tracking branch 'origin/dev' into dev
56faafe
working without try_catch
4a03d49
critical comment processed
3187ec3
del static fields
c359fcc
the remaining part has been corrected
1a12bfc
del comments,rename variable
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,60 @@ | ||
| import java.util.LinkedList; | ||
| import java.util.Locale; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Calc { | ||
| private double goodsSum; | ||
| private final int numPeople; | ||
| private String goodsStr = ""; | ||
| private final Scanner scan; | ||
| private final LinkedList<Product> list; | ||
|
|
||
| Calc(int nPeople, Scanner scan) { | ||
| numPeople = nPeople; | ||
| this.scan = scan; | ||
| list = new LinkedList<>(); | ||
| } | ||
|
|
||
|
|
||
| void goodsAdd() { | ||
| while (true) { | ||
| double priceProduct = -1; | ||
| System.out.println("Введите название товара:"); | ||
| String nameProduct = scan.nextLine(); | ||
| if (nameProduct.length() > 0) { | ||
| System.out.println("Введите цену товара в формате рубли.копейки:"); | ||
| if (scan.hasNextDouble()) { | ||
| priceProduct = scan.nextDouble(); | ||
| } else { | ||
| while (true) { | ||
| if (!(scan.nextLine().equals(""))) break; | ||
| } | ||
| } | ||
| } | ||
| if (priceProduct > 0) { | ||
| System.out.println("Товар " + nameProduct + " по цене " + String.format(Locale.ENGLISH, "%.2f", priceProduct) + " успешно добавлен!"); | ||
| list.add(new Product(nameProduct, priceProduct)); | ||
| goodsStr = goodsStr.concat("\n" + nameProduct); | ||
| goodsSum += priceProduct; | ||
| System.out.println("Добавить следующий товар? (Для выхода введите \"завершить\")"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👏 Круто, что подсказываешь пользователю, как выйти из сценария! |
||
| scan.nextLine(); | ||
| String sel = scan.nextLine(); | ||
| sel = sel.toLowerCase(); | ||
| if (sel.equals("завершить")) { | ||
|
|
||
| System.out.println("Добавленные товары:"); | ||
| for (Product p : list) { | ||
| System.out.println(p.name); | ||
| } | ||
| goodsSum /= numPeople; | ||
| StringBuilder strB = new StringBuilder("Сумма на одного человека: ").append(String.format(Locale.ENGLISH, "%.2f ", goodsSum)).append(Formatter.get(goodsSum)); | ||
| System.out.println(strB); | ||
| break; | ||
| } | ||
| } else { | ||
| System.out.println("Ошибка ввода данных"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
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,10 @@ | ||
| public class Formatter { | ||
| public static String get(double sum) { | ||
| int i = (int) sum % 100; | ||
| int i1 = i % 10; | ||
| int i2 = i / 10; | ||
| if ((i1 == 1) && (i2 != 1)) return "рубль"; | ||
| else if ((i1 > 1) && (i1 < 5) && (i2 != 1)) return "рубля"; | ||
| else return "рублей"; | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
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.Locale; | ||
| import java.util.Scanner; | ||
|
|
||
| public class MainCalc { | ||
| private static int getInt(Scanner scanner) { | ||
| System.out.println("Введите количество человек"); | ||
| while (true) { | ||
| if (scanner.hasNextInt()) { | ||
| int numPeople = scanner.nextInt(); | ||
| if (numPeople > 1) return numPeople; | ||
| } else { | ||
| scanner.next(); | ||
| } | ||
| System.out.println("Ошибка.Введите количество человек еще раз"); | ||
| } | ||
| } | ||
|
|
||
| public static void main(String[] args) { | ||
| Scanner scanner = new Scanner(System.in); | ||
| scanner.useLocale(Locale.ENGLISH); | ||
| int numPeople = getInt(scanner); | ||
| System.out.println("количество человек:" + numPeople); | ||
| scanner.nextLine(); | ||
| Calc clc = new Calc(numPeople, scanner); | ||
| clc.goodsAdd(); | ||
| } | ||
| } |
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,9 @@ | ||
| public class Product { | ||
| public String name; | ||
| public double price; | ||
|
|
||
| Product(String name, double price) { | ||
| this.name = name; | ||
| this.price = price; | ||
| } | ||
| } |
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.
🍏 Можно не просто в строке сохранять имена товаров, а создать отдельный класс Product с полями name и price. Экземпляры этого класса можно сохранить в список. Это может быть удобно, если тебе в дальнейшем потребуется цена каждого товара.