Switch person class usage of Origin class to Country class and use it for distance...
[Persons_Comparator.git] / src / Weight.java
... / ...
CommitLineData
1public class Weight {
2 private int min = 2;
3 private int max = 600;
4 private int defaultWeight = 72;
5 private int weight;
6
7 Weight() {
8 }
9
10 Weight(int weight) {
11 setWeight(weight);
12 }
13
14 public int getMin() {
15 return min;
16 }
17
18 public int getMax() {
19 return max;
20 }
21
22 public int getDefaultWeight() {
23 return defaultWeight;
24 }
25
26 public int getWeight() {
27 return weight;
28 }
29
30 public void setWeight(int weight) {
31 if (validateWeight(weight)) {
32 this.weight = weight;
33 } else {
34 throw new IllegalArgumentException("Weight must be between " + this.getMin() + " and " + this.getMax());
35 }
36 }
37
38 private boolean validateWeight(int weight) {
39 return (weight >= getMin() && weight <= getMax());
40 }
41
42 public Integer[] getValuesArray() {
43 int arrayLength = this.getMax() - this.getMin() + 1;
44 Integer[] intArray = new Integer[arrayLength];
45 for (int i = 0; i < intArray.length; i++) {
46 intArray[i] = this.getMin() + i;
47 }
48 return intArray;
49 }
50
51 public int distanceTo(Weight weight) {
52 int distance = weight.getWeight() - this.getWeight();
53 return Math.abs(distance);
54 }
55}