Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I get an eclipse error that the program and method () is undefined for my game c

ID: 3559902 • Letter: I

Question

I get an eclipse error that the program and method () is undefined for my game classes and I do not know how to add the method play to them. Also if you spot anything wrong with my demo could you let me know, I haven't run it yet because of the errors so I'm not sure if it would run them.

Here is my demo:

import java.util.Scanner;

public class ProjectGames {

   public static void main(String[] args) {  
       int choiceNumber = 0;
       introduction();
       while(choiceNumber != 7)
       {
           printMenuChoices();
           choiceNumber = readChoiceNumber();
           switch (choiceNumber)
           {
           case 1:
               HeadsInARow.HeadsInARowMethod();
               break;
           case 2:
               PrintRandomChart.PrintRandomChartMethod();
               break;
           case 3:
               PatternOFSix.PatternOfSixMethod();
               break;
           case 4:
               RandomDistribution.RandomDistributionMethod();
               break;
           case 5:
               GuessANumber.GuessANumberMethod();
               break;
           case 6:
               FiveDigitNumber.FiveDigitNumberMethod();
               break;
           case 7:
               System.out.println("Thank you for learning the examples.");
               break;
           default:
               System.out.println(" Invalid choice. The game is over.");
               choiceNumber = 8;
               break;
           }//switch

       }//while
   }

   private static void introduction()
   {
       System.out.println(" " +
               " ");
       System.out.println("" +
               " This program deminstrates the framework " +
               " of the games projects. "+
               " " );
   }
   private static void printMenuChoices()
   {
       System.out.println(""+
               " This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "
               + " 1) Throw a particular dice number a certain number of times in a row. "
               + " 2) Build a chart displaying the randomness of the 6 dice numbers. "
               + " 3) Throw a given pattern of six dice. "
               + " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "
               + " 5) Guess the number between 1 and 100. "
               + " 6) Guess a five digit number. "
               + " 7) Quit playing these games. "
               + " Please choose one of the seven choices.");

   }
   private static int readChoiceNumber()
   {
       Scanner scan = new Scanner(System.in);
       int choiceNumber;
       String indent = " ";
       choiceNumber = scan.nextInt();
       while(choiceNumber < 1 || choiceNumber > 2)
       {
           System.out.println(indent + "the number must be 1 through 7 inclusive");
           System.out.println(indent + " please enter a proper choice. ");
           choiceNumber = scan.nextInt();
       }
       return choiceNumber;
   }
}

// This class controls a while loop
class HeadsInARow {

   public HeadsInARow()
   {
       Scanner scan = new Scanner(System.in);
       introduction ();
       Scanner input;
       int dieFaceNumber;
       int numberOfRow;
       int howManyThrows;

   }

   public static void HeadsInARowMethod() {
       // TODO Auto-generated method stub

   }

   private void introduction()
   {
       System.out.println("Throw a particular dice number a certain number of times in a row. ");      
   }
   private void input()
   {
       Scanner input = new Scanner (System.in);
       int howManyThrows = 0;
       System.out.println("This game throws a die until a certain dice face number appears in a row a certain number of times.");
       System.out.println("Please enter the dice face number that you would like to be repeated:");


       int dieFaceNumber = input.nextInt();

       System.out.println("Please enter the number of times you would like " + dieFaceNumber + " to appear in a row:");

       int numberOfRow = input.nextInt();
   }

   public void main(String [] args)
   {
       Scanner input= new Scanner (System.in);
       HeadsInARow game = new HeadsInARow();
       while(true)
       {
           game.input();
           game.process();
           game.input();
           String string1= input.next();

           if (!string1.equals("yes")) break;
       }
   }

   private void process()
   {
       while(true)
       {
           int howManyThrows = (int)((Math.random()*6) + 1);
           int dieFaceNumber = 1;
           int numberOfRow = 0;
           if (howManyThrows == dieFaceNumber)numberOfRow++;
           else break;
       }
   }
   private void output()
   {
       int dieFaceNumber = 0;
       int numberOfRow = 0;
       int howManyThrows = 0;
       System.out.println("It took " + howManyThrows + " throws to get the number " + dieFaceNumber + " to appear " + numberOfRow + " in a row.");
       System.out.println("Would you like to play the game again?");
       System.out.println("Please enter (yes/no)");
   }
private static void printMenuChoices()
{
   System.out.println(""+
           " This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "
           + " 1) Throw a particular dice number a certain number of times in a row. "
           + " 2) Build a chart displaying the randomness of the 6 dice numbers. "
           + " 3) Throw a given pattern of six dice. "
           + " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "
           + " 5) Guess the number between 1 and 100. "
           + " 6) Guess a five digit number. "
           + " 7) Quit playing these games. "
           + " Please choose one of the seven choices.");

}
private static int readChoiceNumber()
{
   Scanner scan = new Scanner(System.in);
   int choiceNumber;
   String indent = " ";
   choiceNumber = scan.nextInt();
   while(choiceNumber < 1 || choiceNumber > 2)
   {
       System.out.println(indent + "the number must be 1 through 7 inclusive");
       System.out.println(indent + " please enter a proper choice. ");
       choiceNumber = scan.nextInt();
   }
   return choiceNumber;
}
}
class PrintRandomChart {

   public PrintRandomChart()
   {
       Scanner keyboard = new Scanner (System.in);
   }
   public static void PrintRandomChartMethod() {
       // TODO Auto-generated method stub

   }
   public void main(String[] args) {
       Scanner keyboard = new Scanner (System.in);
       final int DICE_FACE_COUNT = 6;

       int numberOfTimes;
       int [] diceValues = new int[DICE_FACE_COUNT];
       String response = "yes";
       while (response.compareTo("yes") == 0) {
           for (int i = 0; i < diceValues.length; i++) {
               diceValues[i] = 0;
           }
           System.out.println("Please enter the number of times that");
           System.out.print("you would like to throw the dice: ");
           numberOfTimes = keyboard.nextInt();
           System.out.println("The chart showing " + numberOfTimes + " throws of the dice:");
           while(numberOfTimes > 0) {
               int result = (int)(DICE_FACE_COUNT * Math.random());
               diceValues[result]++;
               numberOfTimes--;
           }
           for (int i = 0; i < diceValues.length; i++) {
               System.out.print(i + 1 + " ");
               for (int astr = 0; astr < diceValues[i]; astr++) {
                   System.out.print("*");

               }
               System.out.println();
           }
           System.out.println(" Would you like to play the game again?");
           System.out.print("Please enter (yes/no) ");
           response = keyboard.next();
           System.out.println();

       }
   }
   private static void printMenuChoices()
   {
       System.out.println(""+
               " This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "
               + " 1) Throw a particular dice number a certain number of times in a row. "
               + " 2) Build a chart displaying the randomness of the 6 dice numbers. "
               + " 3) Throw a given pattern of six dice. "
               + " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "
               + " 5) Guess the number between 1 and 100. "
               + " 6) Guess a five digit number. "
               + " 7) Quit playing these games. "
               + " Please choose one of the seven choices.");

   }
   private static int readChoiceNumber()
   {
       Scanner scan = new Scanner(System.in);
       int choiceNumber;
       String indent = " ";
       choiceNumber = scan.nextInt();
       while(choiceNumber < 1 || choiceNumber > 2)
       {
           System.out.println(indent + "the number must be 1 through 7 inclusive");
           System.out.println(indent + " please enter a proper choice. ");
           choiceNumber = scan.nextInt();
       }
       return choiceNumber;
   }
}
   class PatternOfSix {

       public PatternOfSix() {
           Scanner keyboard = new Scanner(System.in);
           String series;
           System.out.println("Please enter a series of 6 dice that "
                   + "you would like the computer to duplicate");

           series = keyboard.next();
       }
       public String PatternOfSixMethod() {
           return null;
           // TODO Auto-generated method stub

       }

       private String throwPattern() {
           String pattern = "";
           for (int i = 0; i < 6; i++) {
               pattern += "" + (int)(Math.random() * 6 + 1);
           }
           return pattern;
       }

       private int numberOfThrows(String pattern) {
           int count = 0;
           while (!pattern.equals(throwPattern())) {
               count++;
           }
           return count;
       }

       private void printResult(int numberOfThrows, String pattern) {
           System.out.println("It took " + numberOfThrows
                   + " throws to get the pattern " + pattern + " to appear");
       }


       public void main(String[] args) {
           String pattern;
           int throwsNumber;
           String again = "yes";

           while (again.equals("yes")) {
               pattern = PatternOfSixMethod();
               throwsNumber = numberOfThrows(pattern);
               printResult(throwsNumber, pattern);

               System.out.println(" Would you like to play the game again?");
               System.out.print("Please enter (yes/no) ");
               Scanner keyboard = null;
               again = keyboard.next();
               System.out.println();
           }
       }
      
       private static void printMenuChoices()
       {
           System.out.println(""+
                   " This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "
                   + " 1) Throw a particular dice number a certain number of times in a row. "
                   + " 2) Build a chart displaying the randomness of the 6 dice numbers. "
                   + " 3) Throw a given pattern of six dice. "
                   + " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "
                   + " 5) Guess the number between 1 and 100. "
                   + " 6) Guess a five digit number. "
                   + " 7) Quit playing these games. "
                   + " Please choose one of the seven choices.");

       }
       private static int readChoiceNumber()
       {
           Scanner scan = new Scanner(System.in);
           int choiceNumber;
           String indent = " ";
           choiceNumber = scan.nextInt();
           while(choiceNumber < 1 || choiceNumber > 2)
           {
               System.out.println(indent + "the number must be 1 through 7 inclusive");
               System.out.println(indent + " please enter a proper choice. ");
               choiceNumber = scan.nextInt();
           }
           return choiceNumber;
       }
   }
   class RandomDistribution {
       public static void main(String[] args) {
   final int DICE_FACE_COUNT = 6;
   Scanner keyboard = new Scanner (System.in);
   int numberOfTimes;
   int [] diceValues = new int[DICE_FACE_COUNT];
   String response = "yes";
  
   while (response.compareTo("yes") == 0) {
   for (int i = 0; i < diceValues.length; i++) {
   diceValues[i] = 0;
   }
  
   System.out.println("Please enter the number of times that");
   System.out.print("you would like to throw the dice: ");
   numberOfTimes = keyboard.nextInt();
  
   System.out.println("The chart showing " + numberOfTimes + " throws of the dice:");
  
   while(numberOfTimes > 0) {
   int result = (int)(DICE_FACE_COUNT * Math.random());
   diceValues[result]++;
   numberOfTimes--;
   }
  
   for (int i = 0; i < diceValues.length; i++) {
   System.out.print(i + 1 + " ");
   for (int astr = 0; astr < diceValues[i]; astr++) {
   System.out.print("*");
   }
   System.out.println();
   }
  
   System.out.println(" Would you like to play the game again?");
   System.out.print("Please enter (yes/no) ");
   response = keyboard.next();
   System.out.println();
   }
   }
   public static void RandomDistributionMethod() {
           // TODO Auto-generated method stub
          
       }
   private static void printMenuChoices()
   {
       System.out.println(""+
               " This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "
               + " 1) Throw a particular dice number a certain number of times in a row. "
               + " 2) Build a chart displaying the randomness of the 6 dice numbers. "
               + " 3) Throw a given pattern of six dice. "
               + " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "
               + " 5) Guess the number between 1 and 100. "
               + " 6) Guess a five digit number. "
               + " 7) Quit playing these games. "
               + " Please choose one of the seven choices.");

   }
   private static int readChoiceNumber()
   {
       Scanner scan = new Scanner(System.in);
       int choiceNumber;
       String indent = " ";
       choiceNumber = scan.nextInt();
       while(choiceNumber < 1 || choiceNumber > 2)
       {
           System.out.println(indent + "the number must be 1 through 7 inclusive");
           System.out.println(indent + " please enter a proper choice. ");
           choiceNumber = scan.nextInt();
       }
       return choiceNumber;
   }
}
class GuessANumber {
  
   public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
String cont = "yes";
int guess;
int secret;
int count;
  
while (cont.equals("yes")) {
System.out.println("This program allows you to guess a random integer");
System.out.println("between 1 and 100 inclusive. The computer creates");
System.out.println("a random number and tells you if your guess was");
System.out.println("correct, high or low. ");
  
secret = (int)(Math.random() * 100) + 1;
  
System.out.print(" Please guess the number ");
guess = keyboard.nextInt();
count = 1;
  
while (guess != secret) {
System.out.print("You were "
+ (guess > secret ? "high" : "low")
+ ", please guess again ");
guess = keyboard.nextInt();
count++;
}
System.out.println("Good job! You got the number with " + count + " tries.");

System.out.println(" Would you like to play the game again?");
System.out.print("Please enter (yes/no) ");
cont = keyboard.next();
System.out.println();
}
}
   public static void GuessANumberMethod() {
       // TODO Auto-generated method stub
      
   }
   private static void printMenuChoices()
   {
       System.out.println(""+
               " This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "
               + " 1) Throw a particular dice number a certain number of times in a row. "
               + " 2) Build a chart displaying the randomness of the 6 dice numbers. "
               + " 3) Throw a given pattern of six dice. "
               + " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "
               + " 5) Guess the number between 1 and 100. "
               + " 6) Guess a five digit number. "
               + " 7) Quit playing these games. "
               + " Please choose one of the seven choices.");

   }
   private static int readChoiceNumber()
   {
       Scanner scan = new Scanner(System.in);
       int choiceNumber;
       String indent = " ";
       choiceNumber = scan.nextInt();
       while(choiceNumber < 1 || choiceNumber > 2)
       {
           System.out.println(indent + "the number must be 1 through 7 inclusive");
           System.out.println(indent + " please enter a proper choice. ");
           choiceNumber = scan.nextInt();
       }
       return choiceNumber;
   }
}
class FiveDigitNumber {
   public static void main(String[] args) {
       System.out.println("Using the random number generator, this game creates a");
       System.out.println("five-digit number. The player guesses the number.");
       System.out.println("The computer returns two numbers, the first is the number");
       System.out.println("of digits that are in the proper position and the second");
       System.out.println("is the sum of the correct digits guessed so far.");
       System.out.println("The player continues guessing until she guesses the correct number");
       Scanner keyboard = new Scanner(System.in);
       String cont = "yes";

       while (cont.equals("yes")) {
           String secret = String.valueOf((int)(Math.random() * 90000) + 10000);
           String answer = keyboard.next();
           int guesses = 1;
           while (!answer.equals(secret)) {
               int count = 0;
               int sum = 0;
               for (int i = 0; i < 5; i++) {
                   if (answer.charAt(i) == secret.charAt(i)) {
                       count++;
                       sum += Integer.parseInt(answer.substring(i, i + 1));
                   }
               }
               System.out.println("You have found " + count + " digits so far with a sum of " + sum + ". ");
               guesses++;
               answer = keyboard.next();
           }
           System.out.println("It took " + guesses + " guesses to get the number");

           System.out.println("Would you like to play the game again?");
           System.out.print("Please enter (yes/no) ");
           cont = keyboard.next();
       }
   }

   public static void FiveDigitNumberMethod() {
       // TODO Auto-generated method stub
      
   }
}

Explanation / Answer

Hi, I have executed the program in eclipse and it worked with a small correction. Here is the screenshot to show that the program worked. And below is the program (assuming that the program is in a package called chegg.games)

http://snag.gy/M1S0l.jpg

package chegg.games;

import java.util.Scanner;

public class ProjectGames {

public static void main(String[] args) {

int choiceNumber = 0;

introduction();

while(choiceNumber != 7)

{

printMenuChoices();

choiceNumber = readChoiceNumber();

switch (choiceNumber)

{

case 1:

HeadsInARow.HeadsInARowMethod();

break;

case 2:

PrintRandomChart.PrintRandomChartMethod();

break;

case 3:

chegg.games.PatternOfSix.PatternOfSixMethod();

break;

case 4:

RandomDistribution.RandomDistributionMethod();

break;

case 5:

GuessANumber.GuessANumberMethod();

break;

case 6:

FiveDigitNumber.FiveDigitNumberMethod();

break;

case 7:

System.out.println("Thank you for learning the examples.");

break;

default:

System.out.println(" Invalid choice. The game is over.");

choiceNumber = 8;

break;

}//switch

}//while

}

private static void introduction()

{

System.out.println(" " +

" ");

System.out.println("" +

" This program deminstrates the framework " +

" of the games projects. "+

" " );

}

private static void printMenuChoices()

{

System.out.println(""+

" This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "

+ " 1) Throw a particular dice number a certain number of times in a row. "

+ " 2) Build a chart displaying the randomness of the 6 dice numbers. "

+ " 3) Throw a given pattern of six dice. "

+ " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "

+ " 5) Guess the number between 1 and 100. "

+ " 6) Guess a five digit number. "

+ " 7) Quit playing these games. "

+ " Please choose one of the seven choices.");

}

private static int readChoiceNumber()

{

Scanner scan = new Scanner(System.in);

int choiceNumber;

String indent = " ";

choiceNumber = scan.nextInt();

while(choiceNumber < 1 || choiceNumber > 2)

{

System.out.println(indent + "the number must be 1 through 7 inclusive");

System.out.println(indent + " please enter a proper choice. ");

choiceNumber = scan.nextInt();

}

return choiceNumber;

}

}

// This class controls a while loop

class HeadsInARow {

public HeadsInARow()

{

Scanner scan = new Scanner(System.in);

introduction ();

Scanner input;

int dieFaceNumber;

int numberOfRow;

int howManyThrows;

}

public static void HeadsInARowMethod() {

// TODO Auto-generated method stub

}

private void introduction()

{

System.out.println("Throw a particular dice number a certain number of times in a row. ");

}

private void input()

{

Scanner input = new Scanner (System.in);

int howManyThrows = 0;

System.out.println("This game throws a die until a certain dice face number appears in a row a certain number of times.");

System.out.println("Please enter the dice face number that you would like to be repeated:");

?

int dieFaceNumber = input.nextInt();

System.out.println("Please enter the number of times you would like " + dieFaceNumber + " to appear in a row:");

int numberOfRow = input.nextInt();

}

public void main(String [] args)

{

Scanner input= new Scanner (System.in);

HeadsInARow game = new HeadsInARow();

while(true)

{

game.input();

game.process();

game.input();

String string1= input.next();

if (!string1.equals("yes")) break;

}

}

private void process()

{

while(true)

{

int howManyThrows = (int)((Math.random()*6) + 1);

int dieFaceNumber = 1;

int numberOfRow = 0;

if (howManyThrows == dieFaceNumber)numberOfRow++;

else break;

}

}

private void output()

{

int dieFaceNumber = 0;

int numberOfRow = 0;

int howManyThrows = 0;

System.out.println("It took " + howManyThrows + " throws to get the number " + dieFaceNumber + " to appear " + numberOfRow + " in a row.");

System.out.println("Would you like to play the game again?");

System.out.println("Please enter (yes/no)");

}

private static void printMenuChoices()

{

System.out.println(""+

" This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "

+ " 1) Throw a particular dice number a certain number of times in a row. "

+ " 2) Build a chart displaying the randomness of the 6 dice numbers. "

+ " 3) Throw a given pattern of six dice. "

+ " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "

+ " 5) Guess the number between 1 and 100. "

+ " 6) Guess a five digit number. "

+ " 7) Quit playing these games. "

+ " Please choose one of the seven choices.");

}

private static int readChoiceNumber()

{

Scanner scan = new Scanner(System.in);

int choiceNumber;

String indent = " ";

choiceNumber = scan.nextInt();

while(choiceNumber < 1 || choiceNumber > 2)

{

System.out.println(indent + "the number must be 1 through 7 inclusive");

System.out.println(indent + " please enter a proper choice. ");

choiceNumber = scan.nextInt();

}

return choiceNumber;

}

}

class PrintRandomChart {

public PrintRandomChart()

{

Scanner keyboard = new Scanner (System.in);

}

public static void PrintRandomChartMethod() {

// TODO Auto-generated method stub

}

public void main(String[] args) {

Scanner keyboard = new Scanner (System.in);

final int DICE_FACE_COUNT = 6;

int numberOfTimes;

int [] diceValues = new int[DICE_FACE_COUNT];

String response = "yes";

while (response.compareTo("yes") == 0) {

for (int i = 0; i < diceValues.length; i++) {

diceValues[i] = 0;

}

System.out.println("Please enter the number of times that");

System.out.print("you would like to throw the dice: ");

numberOfTimes = keyboard.nextInt();

System.out.println("The chart showing " + numberOfTimes + " throws of the dice:");

while(numberOfTimes > 0) {

int result = (int)(DICE_FACE_COUNT * Math.random());

diceValues[result]++;

numberOfTimes--;

}

for (int i = 0; i < diceValues.length; i++) {

System.out.print(i + 1 + " ");

for (int astr = 0; astr < diceValues[i]; astr++) {

System.out.print("*");

}

System.out.println();

}

System.out.println(" Would you like to play the game again?");

System.out.print("Please enter (yes/no) ");

response = keyboard.next();

System.out.println();

}

}

private static void printMenuChoices()

{

System.out.println(""+

" This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "

+ " 1) Throw a particular dice number a certain number of times in a row. "

+ " 2) Build a chart displaying the randomness of the 6 dice numbers. "

+ " 3) Throw a given pattern of six dice. "

+ " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "

+ " 5) Guess the number between 1 and 100. "

+ " 6) Guess a five digit number. "

+ " 7) Quit playing these games. "

+ " Please choose one of the seven choices.");

}

private static int readChoiceNumber()

{

Scanner scan = new Scanner(System.in);

int choiceNumber;

String indent = " ";

choiceNumber = scan.nextInt();

while(choiceNumber < 1 || choiceNumber > 2)

{

System.out.println(indent + "the number must be 1 through 7 inclusive");

System.out.println(indent + " please enter a proper choice. ");

choiceNumber = scan.nextInt();

}

return choiceNumber;

}

}

class PatternOfSix {

public PatternOfSix() {

Scanner keyboard = new Scanner(System.in);

String series;

System.out.println("Please enter a series of 6 dice that "

+ "you would like the computer to duplicate");

series = keyboard.next();

}

// Here is the changed method (static has been introduced)

public static String PatternOfSixMethod() {

return null;

// TODO Auto-generated method stub

}

private String throwPattern() {

String pattern = "";

for (int i = 0; i < 6; i++) {

pattern += "" + (int)(Math.random() * 6 + 1);

}

return pattern;

}

private int numberOfThrows(String pattern) {

int count = 0;

while (!pattern.equals(throwPattern())) {

count++;

}

return count;

}

private void printResult(int numberOfThrows, String pattern) {

System.out.println("It took " + numberOfThrows

+ " throws to get the pattern " + pattern + " to appear");

}

?

public void main(String[] args) {

String pattern;

int throwsNumber;

String again = "yes";

while (again.equals("yes")) {

pattern = PatternOfSixMethod();

throwsNumber = numberOfThrows(pattern);

printResult(throwsNumber, pattern);

System.out.println(" Would you like to play the game again?");

System.out.print("Please enter (yes/no) ");

Scanner keyboard = null;

again = keyboard.next();

System.out.println();

}

}

private static void printMenuChoices()

{

System.out.println(""+

" This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "

+ " 1) Throw a particular dice number a certain number of times in a row. "

+ " 2) Build a chart displaying the randomness of the 6 dice numbers. "

+ " 3) Throw a given pattern of six dice. "

+ " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "

+ " 5) Guess the number between 1 and 100. "

+ " 6) Guess a five digit number. "

+ " 7) Quit playing these games. "

+ " Please choose one of the seven choices.");

}

private static int readChoiceNumber()

{

Scanner scan = new Scanner(System.in);

int choiceNumber;

String indent = " ";

choiceNumber = scan.nextInt();

while(choiceNumber < 1 || choiceNumber > 2)

{

System.out.println(indent + "the number must be 1 through 7 inclusive");

System.out.println(indent + " please enter a proper choice. ");

choiceNumber = scan.nextInt();

}

return choiceNumber;

}

}

class RandomDistribution {

public static void main(String[] args) {

final int DICE_FACE_COUNT = 6;

Scanner keyboard = new Scanner (System.in);

int numberOfTimes;

int [] diceValues = new int[DICE_FACE_COUNT];

String response = "yes";

while (response.compareTo("yes") == 0) {

for (int i = 0; i < diceValues.length; i++) {

diceValues[i] = 0;

}

System.out.println("Please enter the number of times that");

System.out.print("you would like to throw the dice: ");

numberOfTimes = keyboard.nextInt();

System.out.println("The chart showing " + numberOfTimes + " throws of the dice:");

while(numberOfTimes > 0) {

int result = (int)(DICE_FACE_COUNT * Math.random());

diceValues[result]++;

numberOfTimes--;

}

for (int i = 0; i < diceValues.length; i++) {

System.out.print(i + 1 + " ");

for (int astr = 0; astr < diceValues[i]; astr++) {

System.out.print("*");

}

System.out.println();

}

System.out.println(" Would you like to play the game again?");

System.out.print("Please enter (yes/no) ");

response = keyboard.next();

System.out.println();

}

}

public static void RandomDistributionMethod() {

// TODO Auto-generated method stub

}

private static void printMenuChoices()

{

System.out.println(""+

" This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "

+ " 1) Throw a particular dice number a certain number of times in a row. "

+ " 2) Build a chart displaying the randomness of the 6 dice numbers. "

+ " 3) Throw a given pattern of six dice. "

+ " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "

+ " 5) Guess the number between 1 and 100. "

+ " 6) Guess a five digit number. "

+ " 7) Quit playing these games. "

+ " Please choose one of the seven choices.");

}

private static int readChoiceNumber()

{

Scanner scan = new Scanner(System.in);

int choiceNumber;

String indent = " ";

choiceNumber = scan.nextInt();

while(choiceNumber < 1 || choiceNumber > 2)

{

System.out.println(indent + "the number must be 1 through 7 inclusive");

System.out.println(indent + " please enter a proper choice. ");

choiceNumber = scan.nextInt();

}

return choiceNumber;

}

}

class GuessANumber {

public static void main(String[] args) {

Scanner keyboard = new Scanner(System.in);

String cont = "yes";

int guess;

int secret;

int count;

while (cont.equals("yes")) {

System.out.println("This program allows you to guess a random integer");

System.out.println("between 1 and 100 inclusive. The computer creates");

System.out.println("a random number and tells you if your guess was");

System.out.println("correct, high or low. ");

secret = (int)(Math.random() * 100) + 1;

System.out.print(" Please guess the number ");

guess = keyboard.nextInt();

count = 1;

while (guess != secret) {

System.out.print("You were "

+ (guess > secret ? "high" : "low")

+ ", please guess again ");

guess = keyboard.nextInt();

count++;

}

System.out.println("Good job! You got the number with " + count + " tries.");

System.out.println(" Would you like to play the game again?");

System.out.print("Please enter (yes/no) ");

cont = keyboard.next();

System.out.println();

}

}

public static void GuessANumberMethod() {

// TODO Auto-generated method stub

}

private static void printMenuChoices()

{

System.out.println(""+

" This program allows you to play several games requiring random numbers. The computer generates these random numbers.Which game would you like to play? "

+ " 1) Throw a particular dice number a certain number of times in a row. "

+ " 2) Build a chart displaying the randomness of the 6 dice numbers. "

+ " 3) Throw a given pattern of six dice. "

+ " 4) Find the percent difference for each dice number from the average, given a certain number of throws. "

+ " 5) Guess the number between 1 and 100. "

+ " 6) Guess a five digit number. "

+ " 7) Quit playing these games. "

+ " Please choose one of the seven choices.");

}

private static int readChoiceNumber()

{

Scanner scan = new Scanner(System.in);

int choiceNumber;

String indent = " ";

choiceNumber = scan.nextInt();

while(choiceNumber < 1 || choiceNumber > 2)

{

System.out.println(indent + "the number must be 1 through 7 inclusive");

System.out.println(indent + " please enter a proper choice. ");

choiceNumber = scan.nextInt();

}

return choiceNumber;

}

}

class FiveDigitNumber {

public static void main(String[] args) {

System.out.println("Using the random number generator, this game creates a");

System.out.println("five-digit number. The player guesses the number.");

System.out.println("The computer returns two numbers, the first is the number");

System.out.println("of digits that are in the proper position and the second");

System.out.println("is the sum of the correct digits guessed so far.");

System.out.println("The player continues guessing until she guesses the correct number");

Scanner keyboard = new Scanner(System.in);

String cont = "yes";

while (cont.equals("yes")) {

String secret = String.valueOf((int)(Math.random() * 90000) + 10000);

String answer = keyboard.next();

int guesses = 1;

while (!answer.equals(secret)) {

int count = 0;

int sum = 0;

for (int i = 0; i < 5; i++) {

if (answer.charAt(i) == secret.charAt(i)) {

count++;

sum += Integer.parseInt(answer.substring(i, i + 1));

}

}

System.out.println("You have found " + count + " digits so far with a sum of " + sum + ". ");

guesses++;

answer = keyboard.next();

}

System.out.println("It took " + guesses + " guesses to get the number");

System.out.println("Would you like to play the game again?");

System.out.print("Please enter (yes/no) ");

cont = keyboard.next();

}

}

public static void FiveDigitNumberMethod() {

// TODO Auto-generated method stub

}

}