Skip to content

Домашнее задание по спринту 2#1

Open
il76 wants to merge 5 commits intomainfrom
dev
Open

Домашнее задание по спринту 2#1
il76 wants to merge 5 commits intomainfrom
dev

Conversation

@il76
Copy link
Copy Markdown
Owner

@il76 il76 commented Apr 29, 2024

No description provided.

scanner.useDelimiter("\n");
scanner.useLocale(Locale.ENGLISH); //десятичная точка вместо запятой
System.out.println("Введите список товаров");
while (true) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Не стоит запускать бесконечный цикл прямо в конструкторе класса, лучше вынести это в отдельную функцию, например start(), а в конструкторе класса оставить только конфигурацию объекта и его полей

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

принято

productList.add(product);
PriceFormatter formatter = new PriceFormatter(product.price);
System.out.println("Товар " + product.name + " со стоимостью " + formatter.getFormattedPrice() + " успешно добавлен");
totalAmount += product.price;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

totalAmount можно не считать отдельно, так как возможна рассинхронизация. Для консистентности можно вычислять общую стоимость, пробежавшись по списку товаров в цикле и посчитав сумму всех price

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Не согласен, так как в ТЗ было:

При добавлении товара в калькулятор нужно считать текущую общую сумму всех товаров.

В изначальном варианте был именно отдельный цикл, но исправил после внимательного чтения ТЗ

Comment on lines +5 to +9
double price;
/**
* Название товара
*/
String name;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Поля лучше делать final или private. В случае с private, чтобы изменить значение поля, принято писать функции-сеттеры

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

принято, в спешке забыл

@@ -0,0 +1,34 @@
import java.util.Locale;

public class PriceFormatter {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно функции в этом классе пометить ключевым словом static, чтобы не приходилось каждый раз создавать объект этого класса. Нужно будет ещё price добавить в качестве аргументов функций. Таким образом, можно будет не создавать инстанс класса, а сразу вызывать функции, например PriceFormatter.getFormattedPrice(price)

Copy link
Copy Markdown
Owner Author

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants