Add an ArrayList of persons to the Person class.
[Persons_Comparator.git] / src / Size.java
CommitLineData
1c118933 1public class Size implements Comparable<Size> {
97491195
JB
2 private int max = 240;
3 private int min = 20;
4 private int size;
5
b974e749
JB
6 Size() {
7 }
8
97491195
JB
9 Size(int size) {
10 setSize(size);
11 }
12
13 public int getSize() {
14 return size;
15 }
16
17 public void setSize(int size) {
18 if (validateSize(size)) {
19 this.size = size;
bcdec887 20 } else {
b974e749 21 throw new IllegalArgumentException("Size must be between " + this.min + " and " + this.max);
bcdec887 22 }
97491195
JB
23 }
24
25 private boolean validateSize(int size) {
b974e749 26 return (size >= min && size <= max);
97491195 27 }
1c118933
JB
28
29 @Override
30 public int compareTo(Size size) {
613054ac
JB
31 int distance = size.size - this.getSize();
32 if (distance >= 0)
33 return distance;
34 else
35 return -distance;
36
1c118933 37 }
97491195 38}