forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMelon.java
More file actions
77 lines (64 loc) · 1.63 KB
/
Copy pathMelon.java
File metadata and controls
77 lines (64 loc) · 1.63 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package modern.challenge;
import java.util.Objects;
public class Melon {
enum Sugar {
LOW, MEDIUM, HIGH, UNKONWN
}
private final String type;
private final int weight;
private final Sugar sugar;
public Melon(String type, int weight) {
this.type = type;
this.weight = weight;
this.sugar = Sugar.UNKONWN;
}
public Melon(String type, int weight, Sugar sugar) {
this.type = type;
this.weight = weight;
this.sugar = sugar;
}
public String getType() {
return type;
}
public int getWeight() {
return weight;
}
public Sugar getSugar() {
return sugar;
}
@Override
public String toString() {
return type + "(" + weight + "g)" + (sugar != Sugar.UNKONWN ? " " + sugar : "");
}
@Override
public int hashCode() {
int hash = 7;
hash = 53 * hash + Objects.hashCode(this.type);
hash = 53 * hash + this.weight;
hash = 53 * hash + Objects.hashCode(this.sugar);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Melon other = (Melon) obj;
if (this.weight != other.weight) {
return false;
}
if (!Objects.equals(this.type, other.type)) {
return false;
}
if (!Objects.equals(this.sugar, other.sugar)) {
return false;
}
return true;
}
}