X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2FWeight.java;h=c979f3ddcab3911914e519b71075d4023fe0507a;hb=dcde664f250e05357878e3802a997a81ba93c61a;hp=47547ba4f524711c42a3bc1c3e561fec0be48853;hpb=b974e749af3a4b2df3737b2d361233c704dcc4d8;p=Persons_Comparator.git diff --git a/src/Weight.java b/src/Weight.java index 47547ba..c979f3d 100644 --- a/src/Weight.java +++ b/src/Weight.java @@ -1,4 +1,7 @@ -public class Weight implements Comparable { +public class Weight { + private int min = 2; + private int max = 250; + private int defaultWeight = 72; private int weight; Weight() { @@ -8,6 +11,18 @@ public class Weight implements Comparable { setWeight(weight); } + public int getMin() { + return min; + } + + public int getMax() { + return max; + } + + public int getDefaultWeight() { + return defaultWeight; + } + public int getWeight() { return weight; } @@ -16,20 +31,25 @@ public class Weight implements Comparable { if (validateWeight(weight)) { this.weight = weight; } else { - throw new IllegalArgumentException("Weight cannot be negative or zero"); + throw new IllegalArgumentException("Weight must be between " + this.getMin() + " and " + this.getMax()); } } private boolean validateWeight(int weight) { - return (weight > 0); + return (weight >= getMin() && weight <= getMax()); + } + + public Integer[] getValuesArray() { + int arrayLength = this.getMax() - this.getMin() + 1; + Integer[] intArray = new Integer[arrayLength]; + for (int i = 0; i < intArray.length; i++) { + intArray[i] = this.getMin() + i; + } + return intArray; } - @Override - public int compareTo(Weight weight) { - int distance = weight.weight - this.getWeight(); - if (distance >= 0) - return distance; - else - return -distance; + public int distanceTo(Weight weight) { + int distance = weight.getWeight() - this.getWeight(); + return Math.abs(distance); } }