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

I would like to change DiceGame2 without arrays. DiceGame2 class: package GameDe

ID: 3531956 • Letter: I

Question

I would like to change DiceGame2 without arrays.


DiceGame2 class:


package GameDemo;

import java.util.Scanner;

public class DiceGame2

{

int DICE_FACE_COUNT = 6;

Scanner keyboard = new Scanner (System.in);

int numberOfTimes;

int [] diceValues = new int[DICE_FACE_COUNT];

  

public void play()

{

input();

process();

output();

}


public void input()

{

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

{

diceValues[i] = 0;

}

System.out.println("This game prompts the user for a number of die throws.");

System.out.println("The game then displays a chart indicating the number");

System.out.println("of times the die landed with that face number on top.");

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

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

numberOfTimes = keyboard.nextInt();

}

public void process()

{

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

while(numberOfTimes > 0)

{

int number = (int)(DICE_FACE_COUNT * Math.random()); //0-5 for easier counting

diceValues[number]++;

numberOfTimes--;

}

}

public void output()

{

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.println("Please enter (yes/no) ");

keyboard = new Scanner(System.in);

String choice = keyboard.next();

if (choice.equalsIgnoreCase("yes") || choice.equalsIgnoreCase("y"))

play();

}

}

GameDemo class:

package GameDemo;

import java.util.Scanner;

public class GameDemo

{

static Scanner keyboard = new Scanner(System.in);

  

public static void main(String[] args)

{

int gameChoice = 0;

while(gameChoice != 7)

{

printMenu();

gameChoice = input();

switch(gameChoice)

{

case 1:

DiceGame1 Game1 = new DiceGame1();

Game1.play();

break;

case 2:

DiceGame2 Game2 = new DiceGame2();

Game2.play();

break;

case 3:

DiceGame3 Game3 = new DiceGame3();

Game3.play();

break;

case 4:

DiceGame4 Game4 = new DiceGame4();

Game4.play();

break;

case 5:

RandomGuess Game5 = new RandomGuess();

Game5.play();

break;

case 6:

FiveDigitGuess Game6 = new FiveDigitGuess();

Game6.play();

break;

case 7:

System.out.println("Exiting the demo.");

break;

default:

break;

}

}

}

public static int input()

{

int gameChoice = 0;

while(true)

{

gameChoice = keyboard.nextInt();

if(gameChoice >= 1 && gameChoice <= 7)

break;

else

System.out.println("Try again, 1 through 7 only.");

}

return gameChoice;

}

public static void printMenu()

{

System.out.println("This program allows you to play several games using a random number generator.");

System.out.println("Which game would you like to play?");

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

System.out.println("2) Build a chart displaying the randomness of the 6 die numbers.");

System.out.println("3) Throw a given pattern of six dice.");

System.out.println("4) Find the percent difference for each die number from the average, given a certain number of throws.");

System.out.println("5) Guess the computer generated random number between 1 and 100");

System.out.println("6) Guess a five digit number.");

System.out.println("7) Quit playing these games.");

System.out.println("Please choose one of the 7 choices.");

}

}


Explanation / Answer

when do you need this by?