-
Notifications
You must be signed in to change notification settings - Fork 0
Request for check #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| return currentSum; | ||
| } | ||
|
|
||
| public boolean addItem(Item item) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 Можно вместо boolean добавить void и убрать return, т.к. возвращаемое значение у тебя нигде не используется
| if (lastDigit == 1) { | ||
| rublesValue = "рубль"; | ||
| } else if (lastDigit >= 2 && lastDigit <= 4) { | ||
| rublesValue = "рубля"; | ||
| } else { | ||
| rublesValue = "рублей"; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🍏 Такого рода блоки, как if-then-else, в Java можно заменить на switch case. Дело вкуса
| @@ -0,0 +1,39 @@ | |||
| public class Item { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Круто, что используешь класс, как модель данных для описания товара 👍
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
|
|
||
| Item item = (Item) o; | ||
|
|
||
| if (Double.compare(item.price, price) != 0) return false; | ||
| return name != null ? name.equals(item.name) : item.name == null; | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| int result; | ||
| long temp; | ||
| result = name != null ? name.hashCode() : 0; | ||
| temp = Double.doubleToLongBits(price); | ||
| result = 31 * result + (int) (temp ^ (temp >>> 32)); | ||
| return result; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Весьма полезное решение переопределять hashCode и equals 👍
No description provided.