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

Java You are to create the classic game of Wheel of Fortune. Your application sh

ID: 3776019 • Letter: J

Question

Java You are to create the classic game of Wheel of Fortune. Your application should consist of 3 players, underlines to represent letters in the puzzle, and the available letters. The initial screen should look something like this: Welcome to the Wheel of Fortune Available letters ABCDEFGHIJKLMNOPORSTUVW XYZ Here is the puzzle (Song): Player 1 would you like to Spin (i) or Guess (2) the puzzle? **Note: My puzzle is "SOMEWHERE OVER THE RAINBOW" but pick your own puzzle Notice that Player 1 goes first and can either spin or guess the puzzle by typing a l or 2. If Player 1 spins, then the wheel will spin. To represent the wheel create a random number from 1 to 10. Each will represent a spot on the wheel. Here are the wheel values: Random number 1 $100 Random number 2: $300 Random number 3 S500 Random number 4: S700 Random number 5: S900 Random number 6: $2000 Random number 7: $3000 Random number 8: S5000 Random number 9: $1000 player loses S 1000 from his/her total and loses that turn Random number 10: S0 ll player only loses turn

Explanation / Answer

import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Scanner;

public class GuessPuzzle {
   private static Scanner sc;

   public static void main(String[] args) {
       String puzzleString = null;
       int i = 0;
       Scanner sc = new Scanner(System.in);
       System.out.println("Enter the puzzle string : ");
           puzzleString = takeValidStringOnly();  
       char[] cArray = puzzleString.toCharArray();
       HashMap<Character, Integer> myMap = new HashMap<>();
       int index = 0;
       for (char c : cArray) {
           myMap.put(c, index);
           index++;

       }
       int player = 1;
       while (true) {
          
           System.out.println("Player : " + player + " Would you like to spin(1) or guess the puzzle(2)");
           int choice = takeIntOnly();

           if (choice == 1) {
               int rand = 1 + (int) (Math.random() * 10);

               System.out.println("What is the Letter : ");
               char letter = '';

               letter = takeCharOnly();

               if (myMap.containsKey(letter)) {
                   System.out.println("The letter is there in " + myMap.get(letter) + " position");
               } else {
                   System.out.println("The letter is NOT there");

               }
           } else if (choice == 2) {
               System.out.println("What is your guess : ");
               String guessStr = null;
               try {
                   guessStr = sc.nextLine();
               } catch (InputMismatchException nfe) {
                   System.out.println("What is your guess : ");
                   System.out.println("Please ENTER Valid Input");
                   guessStr = sc.nextLine();
               }
               if (guessStr.equals(puzzleString)) {
                   break;
               }

           }
           player++;
           if(player == 4) {
               player = 1;
           }
       }

   }

   public static int takeIntOnly() {
       sc = new Scanner(System.in);
       int choice = 0;
       try {
           choice = sc.nextInt();
           return choice;
       } catch (InputMismatchException nfe) {
           System.out.println("Please ENTER Valid Input");
           sc.nextLine();
           return takeIntOnly();
       }

   }

   public static char takeCharOnly() {
       sc = new Scanner(System.in);
       char letter = 0;
       try {
           letter = sc.next(".").charAt(0);
           return letter;
       } catch (InputMismatchException nfe) {
           System.out.println("Please ENTER Valid Input");
           sc.nextLine();
           return takeCharOnly();
       }

   }
  
   public static String takeValidStringOnly() {
       sc = new Scanner(System.in);
       String str;
       try {
           str = sc.nextLine();
           if(str.trim().equals("")) {
               throw new InputMismatchException();
           }
           return str;
       } catch (InputMismatchException nfe) {
           System.out.println("Please ENTER Valid Input");
           //sc.nextLine();
           return takeValidStringOnly();
       }

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote