0

I have a question. Below is my driver, I've already written a class. The object of the program is to report a winner and loser based on a coin flip. Heads wins. I already have if (coin1.toString()==coin2.toString()) to take care of a tie. Hoiw do I report a winner for not a tie?
For instance, if Sue gets a heads and Sam gets a tail, how do I report Sue is the winner?

public class Coin2
{

public static void main (String[] args)
{

Coin coin1, coin2;


coin1 = new Coin();
coin2 = new Coin();

coin1.flip();
coin2.flip();
System.out.println ("Sue's toss: " + coin1.toString() + ", Sam's toss: " + coin2.toString());

if (coin1.toString()==coin2.toString())
System.out.println ("It is a tie!");

}
}

1
Contributor
1
Reply
2
Views
12 Years
Discussion Span
Last Post by jengels
0

Nevermind, I figured it out.

if (coin1.toString()!=coin2.toString()&& coin1.isHeads())
System.out.println ("Sue Wins!");

if (coin1.toString()!=coin2.toString()&& coin2.isHeads())
System.out.println ("Sam Wins!");

That solved the problem. I guess I should have tried harder.lol

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.