Add an ArrayList of persons to the Person class.
[Persons_Comparator.git] / src / Size.java
index dfea96cdd8226c8dba12b50fa86423ceb2635658..e665140b9f83c020a1f23ea1dc973ea45ccdbd22 100644 (file)
@@ -1,9 +1,11 @@
-
-public class Size {
+public class Size implements Comparable<Size> {
     private int max = 240;
     private int min = 20;
     private int size;
 
+    Size() {
+    }
+
     Size(int size) {
         setSize(size);
     }
@@ -16,11 +18,21 @@ public class Size {
         if (validateSize(size)) {
             this.size = size;
         } else {
-            throw new IllegalArgumentException("Size must be between" + this.min + " and " + this.max);
+            throw new IllegalArgumentException("Size must be between " + this.min + " and " + this.max);
         }
     }
 
     private boolean validateSize(int size) {
-        return (size > max || size < min);
+        return (size >= min && size <= max);
+    }
+
+    @Override
+    public int compareTo(Size size) {
+        int distance = size.size - this.getSize();
+        if (distance >= 0)
+            return distance;
+        else
+            return -distance;
+
     }
 }