Skip to content

Created BillSplitter console app - #130

Closed
nurlankkz2502 wants to merge 2 commits into
Yandex-Practicum:masterfrom
nurlankkz2502:master
Closed

nurlankkz2502 wants to merge 2 commits into
Yandex-Practicum:masterfrom
nurlankkz2502:master

Conversation

@nurlankkz2502

Copy link
Copy Markdown

No description provided.

Comment thread src/main/java/BillSplitter.java Outdated
List<Product> productList;

BillSplitter(int count) {
totalAmount = 0;

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 сразу при объявлении, а не в конструкторе. А в данном случае можно вообще явно не присваивать ноль, потому что в java при объявлении примитивной переменной без присваивания ей явного значения у неё и так будет дефолтное значение - для инта это 0.

См. здесь в разделе Default Values:
https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

Comment thread src/main/java/BillSplitter.java Outdated
BillSplitter(int count) {
totalAmount = 0;
personCount = count;
productList = new Vector<>();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Также лучше сразу присвоить при объявлении

Comment thread src/main/java/BillSplitter.java Outdated
} else if (integralPart < 10) {
result = String.format("%.2f", value) + " рубля";
} else {
result = String.format("%.2f", value) + " рублей";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Есть принцип, который называется DRY - Don't repeat yourself. По этому принципу, если есть многократные одинаковые фрагменты кода, то их лучше вынести отдельно. Здесь, например, можно отдельно вынести result = String.format("%.2f", value) и к нему в зависимости от суммы добавлять "рубль", "рубля" или "рублей"

Comment thread src/main/java/BillSplitter.java Outdated

productList.add(new Product(productName, productPrice));

totalAmount = totalAmount + productPrice;

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 += productPrice;

Comment thread src/main/java/BillSplitter.java Outdated
totalAmount = totalAmount + productPrice;

System.out.println("Продукт " + productName + " был добавлен");
System.out.println("Вы хотите добавить еще один товар?");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Подряд идущие println лучше объединять в один, делая перенос строки при помощи \n

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.

3 participants