Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

First check solution#1

Open
Secur1ty-21 wants to merge 4 commits intomain from
master
Open

First check solution #1
Secur1ty-21 wants to merge 4 commits intomain from
master

Conversation

@Secur1ty-21
Copy link
Owner

@Secur1ty-21 Secur1ty-21 commented Aug 12, 2022

1.Если возникнут проблемы с отображением кириллицы в консоли, то вот что мне помогло:
Что бы исправить Help menu -> Edit Custom VM Options
добавляем в конец
-Dconsole.encoding=UTF-8
-Dfile.encoding=UTF-8
Перезаходим в студию.

2.Так же реализовал несколько способ ввода для добавления товара т.к. не совсем точно составлено тз
1-й способ Ввод через 2 строки (имя отдельно, цену отдельно)
2-й способ Ввод через одну строку (имя и цена вводиться в одну строку, при этом имя должно быть обернуто в одинарные кавычки)

public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int numOfPeople = getNumOfPeople(); // Колисчестов людей в компании.
Calculator calculator = new Calculator(); // Модель хранения продуктов.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В комментарии написано "Модель хранения продуктов", а класс называется Calculator, это может запутать людей которые читают код

try {
numOfPeople = Integer.parseInt(scanner.nextLine()); // Перехватываем вылет, если пользователь ввел не число
} catch (NumberFormatException e) {
numOfPeople = 0;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

В данном случае если пользователь введет строку "два", то он получит ошибку "Неправильный ввод! Количество человек должно быть > 1, попробуйте ввести еще раз."
Что не совсем однозначно в данной ситуации, возможно стоит в случае ввода не числа выводить другую ошибку?

Comment on lines +31 to +35
try {
numOfPeople = Integer.parseInt(scanner.nextLine()); // Перехватываем вылет, если пользователь ввел не число
} catch (NumberFormatException e) {
numOfPeople = 0;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Тут повторяется код, который написан в 22 - 26 строках
Что бы не повторять одинаковые части кода их можно вынести в функции и вызывать их.

public class Calculator {
private float totalAmount;
// Не Map с сохранением цены т.к. в сохранении цены кажого товора нет необходимости по заданию.
private final List<String> products;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кажется final тут лишний

Copy link
Owner Author

@Secur1ty-21 Secur1ty-21 Aug 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может быть, но насколько помню final позволяет сохранять 1 байт памяти. А присвоение нового инстанца функциональность класса не подразумевает, меняется только внутреннее состояние объекта . Или вопрос в том, что предпочитается помечать final только числовые и текстовые константы, которые явно для этого созданы, чтобы потом не наткнуться на штыки final у своего объекта?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще ты прав, принято накладывать максимально возможные ограничения на объект, а уже если в дальнейшем понадобиться то их можно ослабить

Copy link
Owner Author

@Secur1ty-21 Secur1ty-21 Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Понял, спасибо за пояснения!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@Takexito Takexito Takexito left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /