import java.lang.*;
import java.io.*;
public class UseCoin
{
public static void main(String[] agrs) throws IOException
{
Coin dime;
//Coin.HEADS = false; // ERROR
dime = new Coin(10);
System.out.println(dime);
//dime.face = false; //ERROR
Coin[] pocket;
pocket = new Coin[10];
int sum = 0;
for(int i = 0; (i< pocket.length) && (sum < 100); i++)
{
int cvalue = (int)(Math.random()*25) + 1;
pocket[i] = new Coin(cvalue);
sum +=cvalue;
}
System.out.println("In the pocket: " + sum);
for(int i = 0; i< pocket.length; i++)
{
System.out.println(pocket[i]);
try {
i = System.in.read();
}
catch ( IOException iox ) {
System.out.println( "there was an error: " + iox );
}
System.out.println("pocket["+i+"].compareTo(["+i+"]) = "+pocket[i].compareTo(pocket[i]));
}
}
}
//---------------------------------------------------------------------------------------------------------------------------
public class Coin
{
public static final int HEADS = 0;
public static final int TAILS = 1;
private int value = 1;
private int face;
public Coin()
{
value = 1;
flip();
}
public Coin(int v)
{
value = v;
flip();
}
public void flip()
{
face = (int)(Math.random()*2);
}
public int getValue()
{
return value;
}
public String getFace()
{
if (face == HEADS)
return "HEADS";
else
return "TAILS";
}
public int compareTo( Coin coin )
{
if ( value == coin.getValue() )
{
return 0;
}
else if ( value < coin.getValue() )
{
return -1;
}
else
{
return 1;
}
} // end of compareTo()
public String toString()
{
return "Value: " + value + ", Face: " + getFace();
}
}