Implement eye color compareTo() method.
[Persons_Comparator.git] / src / Size.java
1 public class Size implements Comparable<Size> {
2 private int max = 240;
3 private int min = 20;
4 private int size;
5
6 Size(int size) {
7 setSize(size);
8 }
9
10 public int getSize() {
11 return size;
12 }
13
14 public void setSize(int size) {
15 if (validateSize(size)) {
16 this.size = size;
17 } else {
18 throw new IllegalArgumentException("Size must be between" + this.min + " and " + this.max);
19 }
20 }
21
22 private boolean validateSize(int size) {
23 return (size > max || size < min);
24 }
25
26 @Override
27 public int compareTo(Size size) {
28 int distance = size.size - this.getSize();
29 if (distance >= 0)
30 return distance;
31 else
32 return -distance;
33
34 }
35 }