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!");

}
}

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.