Skip to content

Рестокалькулятор - #1

Open
AlexBaranov23 wants to merge 8 commits into
mainfrom
dev
Open

AlexBaranov23 wants to merge 8 commits into
mainfrom
dev

Conversation

@AlexBaranov23

Copy link
Copy Markdown
Owner

Работает)

if (lastTwoDigits >= 11 && lastTwoDigits <= 14) {
return String.format(format, amount);
} else {
switch (lastDigit) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Можно и так написать, по короче будет

switch (lastDigit) {
                case 1 -> format = "%.2f рубль";
                case 2, 3, 4 -> format = "%.2f рубля";

format = "%.2f рубля";
break;
}
return String.format(format, amount);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Или всю функцию в таком виде

if (lastTwoDigits < 11 || lastTwoDigits > 14) {
            switch (lastDigit) {
                case 1 -> format = "%.2f рубль";
                case 2, 3, 4 -> format = "%.2f рубля";
            }
        }
        return String.format(format, amount);

Тут общее правило такое, если вы видите 2 одинаковых return в 1 функции - с вероятностью 99% её можно сократить без нарушения логики

@@ -0,0 +1,18 @@
public class Product {
private final 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.

Отлично что придерживаетесь инкапсуляции, помечая private поля

@AlexBaranov23

AlexBaranov23 commented Dec 15, 2023 via email

Copy link
Copy Markdown
Owner Author

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