X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FWeight.java;h=e79d1025a9e35977344ab5003e129df1aa88ff03;hb=613054ac3144a04ab284e159b610317eacf67e1f;hp=2a8c8127d7cb17f63cbe5aa8e6a98a26209a3f24;hpb=bcdec88755a4a44882edfbb96581294f77a6e1ed;p=Persons_Comparator.git diff --git a/src/Weight.java b/src/Weight.java index 2a8c812..e79d102 100644 --- a/src/Weight.java +++ b/src/Weight.java @@ -1,4 +1,4 @@ -public class Weight { +public class Weight implements Comparable { private int weight; Weight(int weight) { @@ -20,4 +20,13 @@ public class Weight { private boolean validateWeight(int weight) { return (weight > 0); } + + @Override + public int compareTo(Weight weight) { + int distance = weight.weight - this.getWeight(); + if (distance >= 0) + return distance; + else + return -distance; + } }