I have to make a program that would ask a user for their guess (heads or tails) and tells them if its correct or not then it has to ask the user if they want to play again. I figured out how to do this but the part that i am stuck on is how to print a summary at the end of this program tracking how many wins and how many losses.
import cs1.Keyboard;
public class CoinToss6
{
public static void main(String[] args)
{
char play= 'p';
{
while (play == 'p' || play == 'P')
{
System.out.prin tln(" I'm flipping the coin... Enter heads or tails.");
String guess= Keyboard.readSt ring();
Coin myCoin= new Coin();
myCoin.flip();
myCoin.toString ();
if(guess.equals IgnoreCase((myC oin.toString()) ))
System.out.prin tln("Your guess is correct");
else
System.out.prin tln("Your guess is not correct");
System.out.prin tln("It's " + myCoin.toString ());
System.out.prin t("If you want to play again press P. Enter anything else if you wish to stop. ");
play= Keyboard.readCh ar();
// summary tracking how many wins and how many losses
}
}
}
}
import cs1.Keyboard;
public class CoinToss6
{
public static void main(String[] args)
{
char play= 'p';
{
while (play == 'p' || play == 'P')
{
System.out.prin tln(" I'm flipping the coin... Enter heads or tails.");
String guess= Keyboard.readSt ring();
Coin myCoin= new Coin();
myCoin.flip();
myCoin.toString ();
if(guess.equals IgnoreCase((myC oin.toString()) ))
System.out.prin tln("Your guess is correct");
else
System.out.prin tln("Your guess is not correct");
System.out.prin tln("It's " + myCoin.toString ());
System.out.prin t("If you want to play again press P. Enter anything else if you wish to stop. ");
play= Keyboard.readCh ar();
// summary tracking how many wins and how many losses
}
}
}
}
Comment