Use the following files:
Coin.java
/**
A coin with a monetary value.
*/
public class Coin implements Measurable
{
private double value;
private String name;
/**
Constructs a coin.
@param aValue the monetary value of the coin.
@param aName the name of the coin
*/
public Coin(double aValue, String aName)
{
value = aValue;
name = aName;
}
/**
Gets the coin value.
@return the value
*/
public double getValue()
{
return value;
}
public double getMeasure()
{
return value;
}
/**
Gets the coin name.
@return the name
*/
public String getName()
{
return name;
}
/**
Returns a string representation of the object.
@return name and value of coin
*/
public String toString()
{
return "Coin[value=" + value + ",name=" + name + "]";
}
}
Measurable.java
/**
Describes any class whose objects can be measured.
*/
public interface Measurable
{
/**
Computes the measure of the object.
@return the measure
*/
double getMeasure();
}
MinMaxTester.java
public class MinMaxTester
{
public static void main(String[] args)
{
Coin[] coins =
{
new Coin(0.1, "Dime"),
new Coin(0.05, "Nickel"),
new Coin(0.01, "Penny"),
new Coin(0.25, "Quarter")
};
Pair<Coin, Coin> mm = PairUtil.minmax(coins);
System.out.println(mm.getFirst());
System.out.println("Expected: Coin[value=0.01,name=Penny]");
System.out.println(mm.getSecond());
System.out.println("Expected: Coin[value=0.25,name=Quarter]");
}
}
Pair.java
public class Pair<T, S>
{
private T first;
private S second;
public Pair(T firstElement, S secondElement)
{
first = firstElement;
second = secondElement;
}
public T getFirst()
{
return first;
}
public S getSecond()
{
return second;
}
}