Die - // six if the parameter is invalid. Initial face is 1.

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

View Full Document Right Arrow Icon
//******************************************************************** // Die.java Author: Lewis and Loftus // // Solution to Programming Project 4.3 // // Represents one die (singular of dice) with faces showing values // between 1 and the number of faces on the die. //******************************************************************** / public class Die { private final int MIN_FACES = 4; private int numFaces; // number of sides on the die private int faceValue; // current value showing on the die //----------------------------------------------------------------- // Defaults to a six-sided die, initially showing 1. //----------------------------------------------------------------- public Die () { numFaces = 6; faceValue = 1; } //----------------------------------------------------------------- // Explicitly sets the size of the die. Defaults to a size of
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: // six if the parameter is invalid. Initial face is 1. //-----------------------------------------------------------------public Die (int faces) { if (faces < MIN_FACES) numFaces = 6; else numFaces = faces; faceValue = 1; } //-----------------------------------------------------------------// Rolls the die and returns the result. //-----------------------------------------------------------------public int roll () { faceValue = (int) (Math.random() * numFaces) + 1; return faceValue; } //-----------------------------------------------------------------// Returns the current die value. //-----------------------------------------------------------------public int getFaceValue () { return faceValue; } }...
View Full Document

Ask a homework question - tutors are online