Percent implements Comparable<Percent> { @Override public int compareTo(Percent o) { return Double.compare(percent, o.percent); } Percent(String value);  Percent(int value);  Percent(double value); double getValue(); double getPercent(); @Override String toString(); String toString(int precision); @Override boolean equals(Object obj); @Override int hashCode(); @Override int compareTo(Percent o); static final Percent ZERO; static final Percent HUNDRED; }
@Test public void testCompareTo() { Percent p1 = new Percent(1); Percent p2 = new Percent(2); Percent p4 = new Percent(1.000); assertTrue(p1.compareTo(p1) == 0); assertTrue(p1.compareTo(p2) < 0); assertTrue(p2.compareTo(p1) > 0); assertTrue(p1.compareTo(p4) == 0); }