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

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

Open
MaxSatin wants to merge 14 commits intodev from
devPull
Open

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

Conversation

@MaxSatin
Copy link
Owner

@MaxSatin MaxSatin commented Feb 15, 2024

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

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

double sum;
int divide;
Copy link

@ArturNurtdinov ArturNurtdinov Feb 15, 2024

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

@ArturNurtdinov ArturNurtdinov Feb 15, 2024

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

@ArturNurtdinov ArturNurtdinov Feb 15, 2024

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

@ArturNurtdinov ArturNurtdinov Feb 15, 2024

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

@ArturNurtdinov ArturNurtdinov Feb 15, 2024

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;
finalString name;
finaldouble price;

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

Copy link
Owner Author

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

ArturNurtdinov reacted with heart emoji

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

@ArturNurtdinov ArturNurtdinov Feb 16, 2024

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

Reviewers

1 more reviewer

@ArturNurtdinov ArturNurtdinov ArturNurtdinov 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 によって変換されたページ (->オリジナル) /