-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathItem.java
More file actions
45 lines (36 loc) · 1.11 KB
/
Item.java
File metadata and controls
45 lines (36 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.example.shop;
import java.math.BigDecimal;
import java.util.Objects;
public class Item {
private final String name;
private final BigDecimal price;
private int quantity;
private final BigDecimal discountPercentage;
public Item(String name, BigDecimal price, int quantity) {
this.name = name;
this.price = price;
this.quantity = quantity;
this.discountPercentage = BigDecimal.ZERO;
}
public String getName() {
return name;
}
public BigDecimal getPrice() {
return price;
}
public int getQuantity() {
return quantity;
}
@Override
public boolean equals(Object o) {
if (!(o instanceof Item item)) return false;
return quantity == item.quantity && Objects.equals(name, item.name) && Objects.equals(price, item.price) && Objects.equals(discountPercentage, item.discountPercentage);
}
@Override
public int hashCode() {
return Objects.hash(name, price, quantity, discountPercentage);
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
}