forked from PacktPublishing/Java-Coding-Problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMelon.java
More file actions
65 lines (53 loc) · 1.27 KB
/
Melon.java
File metadata and controls
65 lines (53 loc) · 1.27 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
package modern.challenge;
import java.util.Objects;
public class Melon {
private String type;
private int weight;
public Melon(String type, int weight) {
this.type = type;
this.weight = weight;
}
public String getType() {
return type;
}
public int getWeight() {
return weight;
}
public void setType(String type) {
this.type = type;
}
public void setWeight(int weight) {
this.weight = weight;
}
@Override
public String toString() {
return type + "(" + weight + "g)";
}
@Override
public int hashCode() {
int hash = 7;
hash = 37 * hash + Objects.hashCode(this.type);
hash = 37 * hash + this.weight;
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;
}
return true;
}
}