import javax.swing.*;
import java.util.*;
class Chapter9_23{
public static void main(String []args){
String secretWord = JOptionPane.showInputDialog(null, "\tPlayer One\nInput Phrase For Player Two: ");
String shuffleSecret = Shuffle.shuffle(secretWord);
System.out.println("Hint : " + shuffleSecret);
int hint = JOptionPane.showConfirmDialog(null, "Player One\nDo You Want To Give A Hint?");
if (hint == 0){
String hintYes = JOptionPane.showInputDialog(null, "Player One\nInput Second Hint: ");
System.out.print("Hint #2 : " + hintYes);
}
String playerTwo = JOptionPane.showInputDialog(null, "Player Two\nYou Have One Chance To Guess Correctly.\nInput Guess : \n\n*NOTE: CASE SENSITIVE!");
if (playerTwo.equals(secretWord)){
JOptionPane.showMessageDialog(null, "CONGRADULATIONS! YOU WON!");
}
else {
JOptionPane.showMessageDialog(null, "GAME OVER!\nCorrect Answer Was : " + secretWord);
}
System.exit(0);
}
}
import javax.swing.*;
import java.util.*;
class Shuffle{
static String shuffle(String secretWord){
int wordAmt = secretWord.length();
if (wordAmt <= 1){
return secretWord;
}
int arraySecret[] = new int[wordAmt];
for (int i = 0; i < arraySecret.length; i++){
arraySecret[i] = Math.random();
}
}
}
I'm struggling with my array. I need to come up with a game that allows a player to guess a secret word that has been shuffled or randomized. My problem is that i'm not sure how to randomize my secret word. My main problem lies in the for loop of the shuffle class. Any suggestions on how to finish my shuffling?

New Topic/Question
Reply



MultiQuote




|