X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FSize.java;h=c2392073b34662affdc474f619a1ab27519e2a98;hb=6b48f5704ad227586a57e15fdeade02e7d7332f7;hp=0cecada6c98192f7cfa94f874f937e1fe9831276;hpb=9749119587561f5848349b7a1b9e7d9342944f0d;p=Persons_Comparator.git diff --git a/src/Size.java b/src/Size.java index 0cecada..c239207 100644 --- a/src/Size.java +++ b/src/Size.java @@ -1,5 +1,4 @@ - -public class Size { +public class Size implements Comparable { private int max = 240; private int min = 20; private int size; @@ -15,10 +14,22 @@ public class Size { public void setSize(int size) { if (validateSize(size)) { this.size = size; - } /* FIXME: raise an error */ + } else { + throw new IllegalArgumentException("Size must be between" + this.min + " and " + this.max); + } } private boolean validateSize(int size) { return (size > max || size < min); } + + @Override + public int compareTo(Size size) { + int distance = size.size - this.getSize(); + if (distance >= 0) + return distance; + else + return -distance; + + } }