Write a menu class that runs 6 game classes. The menu class has three methods: one for introducing the games program to the client, one that reads the input guaranteeing that the input is between 1 and 7 inclusive, and one for printing the menu. Please use a switch statement to choose one of the 7 choices, and a while loop to allow the client to continue playing games if he wishes. Create 6 more classes that are "stubs" of the six games that you will write as solutions for the next six projects. These stubs can be called from the Menu program, and can be used to test the syntax of the Menu program. Once the Menu program is written and debugged you can start replacing each stub with a game that satisfies the next 6 projects. Below is the sample output of the menu: This program allows you to play several games requiring random numbers. The computer generates these random numbers. Which game would you like to play? Throw a dice number a certain number of times in a row. Demonstrate the randomness of the random number generator. Throw a given pattern of six dice. Find the percent difference for each dice number from the average, given a certain number of throws. Tic Tac Toe. Guess a five digit number.

Respuesta :

Answer:

Explanation:

1. Menu.java

-------------------------------------------------------------------

/**

*

*/

package game;

/**

* Class Menu. Display list of games and allows to play a game as per choice

*

*/

import java.util.Scanner;

public class Menu {

  // displays introduction to program

  private static void intro() {

      System.out.println(

              "This program allows you to play several games requiring random numbers. The computer generates these random numbers.\n"

                      + "Which game would you like to play?\n"

                      + "1. Throw a dice number a certain number of times in a row.\n"

                      + "2. Demonstrate the randomness of the random number generator.\n"

                      + "3. Throw a given pattern of six dice.\n"

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

                      + "5. Tic Tac Toe.\n" + "6. Guess a five digit number.\n" + "7. Quit playing these games.\n"

                      + "Please choose one of the 7 choices.\n" + "-------------------------------------\n\n");

  }

  // gets user input

  private static int getInput(Scanner in) {

      int x;

      while (true) {

          x = in.nextInt();

          if (x <= 7 && x >= 1) {

              System.out.println("Your choice " + x);

              break;

          } else {

              System.out.println("Wrong input! Please enter a value between 1 and 7");

          }

      }

      return x;

  }

  // prints menu

  private static void printMenu() {

      System.out.println("Select from the list below: \n" + "1. DieFaceInARow \n" + "2. RandomNumberGenerator \n"

              + "3. PatternOfSix \n" + "4. RandomNumberDistribution \n" + "5. Game 5 \n" + "6. Game 6 \n"

              + "7. Exit \n");

  }

  // main function

  public static void main(String args[]) {

      intro(); // display introduction to program

      // while loop allowing user to select a choice until exiting.

      while (true) {

          printMenu(); // prints menu

          int x = getInput(new Scanner(System.in)); // choice of user

          switch (x) {

          case 1:

              new DieFaceInARow();

              break;

          case 2:

              new RandomNumberGenarator();

              break;

          case 3:

              new PatternOfSix();

              break;

          case 4:

              new RandomDistribution();

              break;

          case 5:

              new TicTacToe();

              break;

          case 6:

              new GuessFiveDigitNumber();

              break;

          case 7:

              System.out.println("Thank you for playing the game. See you next time!");

              System.exit(1);

          }

      }

  }

}

--------------------------------------------

2. DieFaceInARow.java: Stub for DieFaceInARow class

----------------------------------------

package game;

/**

* Class DieFaceInARow

*

*/

class DieFaceInARow {

  /**

  * Default constructor

  */

  public DieFaceInARow() {

      System.out.println("Calling DieFaceInARow constructor...");

  }

}

---------------------------------------------------

3. RandomNumberGenerator.java: Stub for RandomNumberGenerator class

---------------------------------------------------

package game;

/**

* Class RandonNumberGenarator

*/

class RandomNumberGenarator {

  /**

  * Default constructor

  */

  public RandomNumberGenarator() {

      System.out.println("Calling RandomNumberGenarator constructor...");

  }

}

---------------------------------------------------------

4. PatternOfSix.java: Stub for PatternOfSix class

--------------------------------------------

package game;

/**

* Class PatternOfSix

*/

class PatternOfSix {

  /**

  * Default constructor

  */

  public PatternOfSix() {

      System.out.println("Calling PatternOfSix constructor...");

  }

}

-------------------------------------------------------------

5. RandomDistribution.java: Stub for RandomDistribution class

------------------------------------------------------------

package game;

/**

* Class RandonDistribution *

*/

class RandomDistribution {

  /**

  * Default constructor

  */

  public RandomDistribution() {

      System.out.println("Calling RandonDistribution constructor...");

  }

}

--------------------------------------------------------------------------

6. TicTacToe.java: Stub for TicTacToe.java

------------------------------------------------------------------

package game;

/**

* Class TicTacToe

*/

class TicTacToe {

  /**

  * Default constructor

  */

  public TicTacToe() {

      System.out.println("Calling TicTacToe constructor...");

  }

}

-----------------------------------------------

7. GuessFiveDigitNumber.java: Stub for GuessFiveDigitNumber class

-----------------------------------------------

package game;

/**

* Class GuessFiveDigitNumber

*/

class GuessFiveDigitNumber {

  /**

  * Default constructor

  */

  public GuessFiveDigitNumber() {

      System.out.println("Calling GuessFiveDigitNumber constructor...");

  }

}

-------------------------------------------------------------------

Note: Problem statement of Assignment 8 is not complete.

ACCESS MORE