Skip to content

Pull Request. Приложение калькулятор#1

Open
MaxSatin wants to merge 14 commits intodevfrom
devPull
Open

Pull Request. Приложение калькулятор#1
MaxSatin wants to merge 14 commits intodevfrom
devPull

Conversation

@MaxSatin
Copy link
Copy Markdown
Owner

Домашняя работа. Приложение калькулятор.

Comment on lines +6 to +10
ArrayList<Products> productList = new ArrayList<>();
Scanner scanner = new Scanner(System.in);

double sum;
int divide;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Поля лучше делать максимально ограниченными по видимости, в данном случае рекомендую сделать private

Comment on lines +62 to +67
System.out.println("Продукт " + productNew.name + " стоимостью "
+ (Math.round(productNew.price * 100.0)/100.0) +
" " + formatter((Math.round(productNew.price * 100.0)/100.0))
+ " добавлен в список.\nОбщая сумма составляет: "
+ (Math.round((sum) * 100.0)/100.0) +
" " + formatter((Math.round((sum) * 100.0)/100.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.

Конкатенацию строк не стоит использовать в циклах из-за её затрат по памяти и скорости работы. Предпочтительнее использовать класс StringBuilder или форматирование с помощью String.format

" " + formatter ((Math.round(sum * 100.0)/100.0)));

int name = divide;
double finalSum = sum / divide;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Эта строчка станет в разы понятнее, если divide переименовать в peopleCount, например

" " + formatter ((Math.round(finalSum * 100.0)/100.0)));
}

public String formatter (double number) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

В этой функции дополнительно нужно учесть, что для чисел, которые оканчиваются на 11-19 включительно, необходимо выводить слово "рублей"

Comment on lines +2 to +3
String name;
double 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.

Эти два поля могут быть константными:

Suggested change
String name;
double price;
final String name;
final double price;

Это исключит их изменение извне

@MaxSatin
Copy link
Copy Markdown
Owner Author

Артур, привет!
Спасибо большое за правки, постарался все исправить как ты сказал.

Comment on lines +86 to +87
template = "Итоговая сумма: %.2f %s";
System.out.println(String.format(template, sum, formatter(sum)));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

template лучше не писать, а сразу всё в одном вызове писать, иначе потом запутаешься с этой переменной сам

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