|
|
|
This was the fist time I used arrays.
It confused the hell out of me. I've got it now though so there's no need to worry. For any of you who
played the game clue before will somewhat understand this alittle better. The game is not actually played.
It randomly chooses a murderer, a weapon and a location and displays it on the screen.
/**Name of Program File: Clue.java
Author: Travis McGrath
INFO140 Section # Date: Oct. 26, 2001
Your Company Name: Private Invetigators Training School
Description: This program will generate a murder scenario. It will randomly
select a murderer, a location and a weapon from among the possibilities
available. Any combination of murderer, location and weapon forms a
potential scenario.*/
public class Clue
{
public static void main(String[] args)
{
//explain program to user
System.out.println("This program will generate a murder scenario. " +
"It will randomly select a murderer, a location and a weapon from ");
System.out.println("among the possibilities available. Any " +
"combination of murderer, location and weapon forms a potential " +
"scenario.");
//declare, instantiate and initialize three String arrays
String[] murderersArray = {"Colonal Mustard",
"Miss Scarlet", "Professor Plum", "Mrs. White", "Reverend Green",
"Mrs. Peacock"};
String[] locationsArray = {"conservatory",
"dinning room", "lavatory", "hall", "lounge", "kitchen", "ball room",
"library", "study"};
String[] weaponsArray = {"candle stick", "rope",
"dagger", "lead pipe", "revolver", "wrench"};
//get random numbers
int murderer = (int)(Math.random()*5);
int location = (int)(Math.random()*8);
int weapon = (int)(Math.random()*5);
//display the resalts
System.out.println("");
System.out.println("It was " + murderersArray[murderer] +
" in the " + locationsArray[location] + ", with the "
+ weaponsArray[weapon] + ".");
}//end main
}//end class
|