Implement the person comparator :
[Persons_Comparator.git] / src / Size.java
1 public class Size {
2 private int max = 240;
3 private int min = 40;
4 private int defaultSize = 160;
5 private int size;
6
7 Size() {
8 }
9
10 Size(int size) {
11 setSize(size);
12 }
13
14 public int getMin() {
15 return min;
16 }
17
18 public int getMax() {
19 return max;
20 }
21
22 public int getDefaultSize() {
23 return defaultSize;
24 }
25
26 public int getSize() {
27 return size;
28 }
29
30 public void setSize(int size) {
31 if (validateSize(size)) {
32 this.size = size;
33 } else {
34 throw new IllegalArgumentException("Size must be between " + this.getMin() + " and " + this.getMax());
35 }
36 }
37
38 private boolean validateSize(int size) {
39 return (size >= getMin() && size <= getMax());
40 }
41
42 public int distanceTo(Size size) {
43 int distance = size.getSize() - this.getSize();
44 return Math.abs(distance);
45 }
46 }