Question: Java. Here is a Coin class that is supposed to represent a coin that can be tossed to come up with heads or tails, 50/50

Java. Here is a Coin class that is supposed to represent a coin that can be tossed to come up with heads or tails, 50/50 chance for each possibility.

public class Coin { boolean isHeads; // true if the coin is currently heads up, false otherwise.

 public Coin() {//fill this constructor in} 

public void flip() { if (Math.random() >= 0.5)

isHeads = true;

else

isHeads = false;

}

}

Question: Design and write code for a GuessCoin class that allows the user to specify the likelihood that the coin will come up heads vs tails. GuessCoin should be a subclass of Coin (GuessCoin extends Coin), and should have a constructor GuessCoin(double percent) that allows the user to specify the percentage of the time the coin comes up heads. percent will be a number between 0 and 1, with 0=0%, and 1=100%. Also override flip() correctly, and add any other methods that you need to, if at all.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!