import java.util.*;
import java.io.*;
public class Coin {
private String face;
private int tosses;
private int heads;
private double prob = 0.5; // another way to initialize
private int value;
public void initCoin(String f, Double p) {
face = f;
tosses=0;
heads=0;
prob=p;
}
public Coin(int v) {
value = v;
initCoin("Heads",0.5);
}
public Coin() {
initCoin("Heads",0.5);
}
public Coin(String f) {
initCoin(f,0.5);
}
public String getFace() {
return face;
}
public boolean equal (Coin other) {
/* changed from equals to equal because I didn't want to override the givern .equals method */
return face.equals(other.getFace());
}
public int getValue() {
return value;
}
public String toString() {
return ""+value+" cents";
}
public void setFace (String f) {
face = f;
}
public void flip() {
// generate a random number and set face to heads
// or tails
double r;
tosses = tosses + 1;
r = Math.random ();
if (r <= prob) {
setFace ("heads");
}
else {
setFace ("tails");
}
}
}