repositories
/
Persons_Comparator.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix .compareTo() calculation in Size and Weight classes.
[Persons_Comparator.git]
/
src
/
Size.java
diff --git
a/src/Size.java
b/src/Size.java
index a526fab6a01a3fb9ce5d5ce31b5f39aef3d3bae2..6946e5a8967e2358072fccd1fb7fa13e619e9f9d 100644
(file)
--- a/
src/Size.java
+++ b/
src/Size.java
@@
-1,10
+1,11
@@
-import java.util.Comparator;
-
public class Size implements Comparable<Size> {
private int max = 240;
private int min = 20;
private int size;
public class Size implements Comparable<Size> {
private int max = 240;
private int min = 20;
private int size;
+ Size() {
+ }
+
Size(int size) {
setSize(size);
}
Size(int size) {
setSize(size);
}
@@
-17,16
+18,21
@@
public class Size implements Comparable<Size> {
if (validateSize(size)) {
this.size = size;
} else {
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) {
}
}
private boolean validateSize(int size) {
- return (size >
max || size < min
);
+ return (size >
= min && size <= max
);
}
@Override
public int compareTo(Size size) {
}
@Override
public int compareTo(Size size) {
- return 0;
+ int distance = size.getSize() - this.getSize();
+ if (distance >= 0)
+ return distance;
+ else
+ return -distance;
+
}
}
}
}