Die - die has // int getFace(): Takes no parameters and...

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

View Full Document Right Arrow Icon
// File: Die.java // Author: Amber Settle, Gian Mario Besana, and others // Purpose: To show a programmer-defined class // Constructors: // Die(int faces): Takes as a parameter a number representing the // possible faces the die can have. Typically this // will be 6, but it could be 4, 8, 12, or 20 // Methods: // void roll(): Takes no parameters and sets the face that is showing // on the die to a random number between the minimum number of // faces (here 1) and the maximum number of faces the
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: die has // int getFace(): Takes no parameters and returns the value of the face // that is showing public class Die { private int MAX_NUMBER; private static final int MIN_NUMBER = 1; private static final int NO_NUMBER = 0; private int number; public Die(int faces) { number = NO_NUMBER; MAX_NUMBER = faces; } public void roll () { number = (int) (Math.floor(Math.random()*(MAX_NUMBER-MIN_NUMBER + 1)) +MIN_NUMBER); } public int getFace() { return number; } }...
View Full Document

This note was uploaded on 03/05/2011 for the course CSCI 384 taught by Professor Drchan during the Spring '11 term at CA Health Sciences.

Ask a homework question - tutors are online