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

I get the eclipse error the method play is undefined for type DiceGame2 Here is

ID: 3642503 • Letter: I

Question

I get the eclipse error the method play is undefined for type DiceGame2

Here is my Demo where I'm getting the error:

import java.util.Scanner;
public class GameDemo {

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

public static void main(String[] args) {
int GameChoice = 0;
DiceGame Game1 = new DiceGame();
DiceGame2 Game2 = new DiceGame2();
DiceGame3 Game3 = new DiceGame3();
DiceGame4 Game4 = new DiceGame4();
RandomGuess Game5 = new RandomGuess();
SkillGuess Game6 = new SkillGuess();

while(GameChoice != 7) {
menu();
GameChoice = input();

switch(GameChoice) {
case 1:
Game1.play();
break;
case 2:
Game2.play(); //Here is the error
break;
case 3:
Game3.play();
break;
case 4:
Game4.play();
break;
case 5:
Game5.play();
break;
case 6:
Game6.play();
break;
case 7:
System.out.println("Closing the demo.");
break;
default:
break;
}
}
}

public static int input() {
int gameChoice = 0;
while(true) {
gameChoice = scan.nextInt();
if(gameChoice == 0)
menu();
if(gameChoice > 0 && gameChoice <= 7)
break;
else
System.out.println("Try again, 1 through 7 only. 0 for the menu again.");
}
return gameChoice;
}

public static void menu() {
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 number between 1 and 100");
System.out.println("6) Guess a five digit number.");
System.out.println("7) Quit playing.");
System.out.println("Please choose one of the 7 choices.");
}
}


Here is DiceGame2: Where I need the method added



import java.util.Scanner;
public class DiceGame2 {
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();



}
}
}


I'm actually having that error for all of the games except the first one, so if anyone has any pointers that would be great too.

Explanation / Answer

So your switch block will become:
switch(GameChoice) {
case 1:
Game1.main(null);
break;
case 2:
Game2.main(null);
break;
case 3:
Game3.main(null);
break;
case 4:
Game4.main(null);
break;
case 5:
Game5.main(null);
break;
case 6:
Game6.main(null);
break;
case 7:
System.out.println("Closing the demo.");
break;
default:
break;
}
}
}

Please rate one answer lifesaver, and the other, whatever you like.