Coin - // Returns the current face of the coin as an...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
// ******************************************************************* // Coin.java Author: Lewis and Loftus // // Represents a coin with two sides that can be flipped. // ******************************************************************* public class Coin { public final int HEADS = 0; public final int TAILS = 1; private int face; // --------------------------------------------- // Sets up the coin by flipping it initially. // --------------------------------------------- public Coin () { flip(); } // ----------------------------------------------- // Flips the coin by randomly choosing a face. // ----------------------------------------------- public void flip() { face = (int) (Math.random() * 2); } // -----------------------------------------------------
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // Returns the current face of the coin as an integer. // -----------------------------------------------------public int getFace() { return face; } // ---------------------------------------------------------// Returns true if the current face of the coin is heads. // ---------------------------------------------------------public boolean isHeads() { return (face == HEADS); } // ----------------------------------------------------// Returns the current face of the coin as a string. // ----------------------------------------------------public String toString() { String faceName; if (face == HEADS) faceName = "Heads"; else faceName = "Tails"; return faceName; } }...
View Full Document

This note was uploaded on 03/22/2010 for the course CS 202 taught by Professor Fong during the Spring '10 term at SIU Carbondale.

Page1 / 2

Coin - // Returns the current face of the coin as an...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online