Loading
notes intro/old submit AP Problems the dump links
 

Methods

 

We want to create a class called DiceAction that will be the most useful class of dice ever:

It will have the following methods: For full credit, Math.random will be used once in rollDie(int sides)

 

  • public int rollDie() //rolls a regular die
  • public int rollDie(int sides) //rolls a sides-sided die
  • public int rollDice() //rolls 2 regular dice returning the total
  • public int rollDice(int howMany)// rolls this number of regular dice and return total
  • public int rollDice(int howMany, int sides) //rolls this number of sides-sided dice and return total
  • public double avgRoll () //rolls 10 regular die and returns the average
  • public double avgRoll (int times) //rolls times regular die and returns the average
  • public double avgRoll (int times, int sides) //rolls times sides-sided die and returns the average
  • public boolean isEven() //rolls a regular die and returns true if even
  • public boolean isEven(int sides) //rolls a sides-sided die and returns true if even

Extra Credit:

  • public char scattegories() // that will return a lower case letter randomly (look at pauls response, and ascii tables)
  • public String scattegories(int length) // that will return a word with length letters where every letter is random and and every other letter is a vowel

Make calls to your other methods to cut down on your coding time.

To test use this code below:


 
public class DiceAction {

	public static void main(String[] args)
	{
		DiceAction myDice=new DiceAction();

		//System.out.println("RollDie returns " + myDice.rollDie());
		//System.out.println("RollDie(sides) returns " + myDice.rollDie(20));
		//System.out.println("rollDice() returns " +  myDice.rollDice());
		//System.out.println("rollDice(5) " + myDice.rollDice(5));
		//System.out.println("rollDice(5,8) " + myDice.rollDice(5,8));
		//System.out.println("avgRoll returns " + myDice.avgRoll());
		//System.out.println("avgRoll(100) returns " + myDice.avgRoll(100));
		//System.out.println("avgRoll(100,10) returns " + myDice.avgRoll(100,10));        
		//System.out.println("isEven() returns " + myDice.isEven());
		//System.out.println("isEven(5) returns " + myDice.isEven(5));

	}
}