Skip to content

Conversation

@VictorBlyakherov
Copy link
Owner

No description provided.

return currentSum;
}

public boolean addItem(Item item) {

Choose a reason for hiding this comment

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

🍏 Можно вместо boolean добавить void и убрать return, т.к. возвращаемое значение у тебя нигде не используется

Comment on lines +13 to +19
if (lastDigit == 1) {
rublesValue = "рубль";
} else if (lastDigit >= 2 && lastDigit <= 4) {
rublesValue = "рубля";
} else {
rublesValue = "рублей";
}

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 {

Choose a reason for hiding this comment

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

Круто, что используешь класс, как модель данных для описания товара 👍

Comment on lines +18 to +37
@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;
}

Choose a reason for hiding this comment

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

Весьма полезное решение переопределять hashCode и equals 👍

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.

4 participants