Coin - public void flip () { face = (int) (Math.random() *...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
//******************************************************************** // Coin.java Author: Lewis and Loftus // // Solution to Programming Project 7.1 // // 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. //-----------------------------------------------------------------
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: public void flip () { face = (int) (Math.random() * 2); } //-----------------------------------------------------------------// Returns the current face of the coin as an integer. //-----------------------------------------------------------------public int getFace () { return face; } //-----------------------------------------------------------------// 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 05/17/2011 for the course COP 3530 taught by Professor Davis during the Spring '08 term at University of Florida.

Ask a homework question - tutors are online