I have a problem to Modify the Coin class to have it implement the Comparable interface. The following code is not working correctly and I don't know why.
public class Coin implements Comparable<Object>
{
private double value;
private String name;
public Coin(double aValue, String aName)
{
value = aValue;
name = aName;
}
public int Coinc1.compareTo(Object c2)
{
return (int) value;
}
}
/**
This program tests the use of the Comparable interface
in the coin class.
*/
public class CoinTester
{
public static void main(String[] args)
{
Coin c1 = new Coin(0.05, "nickel");
Coin c2 = new Coin(0.01, "penny");
int b = c1.compareTo(c2);
if (b < 0)
System.out.println("less");
else if (b > 0)
System.out.println("more");
else
System.out.println("equal");
System.out.println("Expected: more");
}
}