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

The full question is on the picture, please write two full class to get the samp

ID: 3854728 • Letter: T

Question

The full question is on the picture,

please write two full class to get the sample output

thank u

The Game class will have the following attributes:

The secret phrase (an array of char)

The disguised phrase (another array of char), in which each unknown letter in the secret phrase

is replaced with a blank line ( _ ). For example, if the secret phrase is computer science and the letters c and s have been guessed, the disguised phrase would print as

C_ _ _ _ _ _ _ SC _ _ _ C_

The number of guesses made

The number of incorrect guesses

The jackpot amount

Question:1 Consider a class that could be used to play a computer version of the long running TV game Wheel of Fortune http://www.wheeloffortune.com/ On the TV game, there are three players who try and guess a phrase. They get to spin a wheel with different dollar amounts (e.g., $200, $500, $1000, etc). Then they guess a letter. If the letter is in the hidden phrase they get the value that they spun multiplied by the number of the guessed letter in the phrase. For example, if the person spun $200 and guessed 'S' for the hidden phrase "Star Wars", the person would win $400 because there were two letters 'S' in the phrase. The winner of the game is the person who guesses the phrase first and they win all the money that they accumulated during the game. You are going to write a very simple text version of this game. There will only be one player and three dollar amounts ($200, S500 and S1000) that the player will 'spin' before guessing a letter. The player's jackpot (the amount of money they win on each guess) will keep increasing while they guess letters up to a maximum of 6 letter guesses. If they select a letter that is not in the phrase they will not win any money on that turn (but it counts as a turn) and they cannot try to guess the phrase. The game continues until one of the following occurs 1) the player correctly guesses the phrase and they win their 'jackpot, or 2) the player incorrectly guesses the phrase in which case the game is over, the phrase will be revealed and the player does not win any money, or 3) the player uses their last of 6 letter guesses - the player gets to select no more than 6 letters, and if they cannot guess the phrase after the 6th letter guess then the game is over, the phrase is revealed, and the player does not win any money

Explanation / Answer

Given below is the code for the question along with output. In case of any issues, post a comment. If happy with the answer, please rate it. Thank you.

import java.util.Random;

import java.util.Scanner;

public class Game {

   private char[] secret_phrase;

   private char[] disguised_phrase;

   private int guesses;

   private int incorrect;

   private int jackpot;

   private Random random;

   private byte already_guessed[];

   private String[] songs;

   public Game(){

       random = new Random(System.currentTimeMillis());

       already_guessed = new byte[26];

       songs = new String[]{"You Light Up My Life", "We Belong Together","Uptown Funk", "I Just Want to be your everything",

               "One Sweet Day", "How you remind me", "I want to hold your hand", "Call me maybe"};

      

   }

   public int spinWheel(){

       int amount[] = {200, 500, 1000};

       return amount[random.nextInt(amount.length)];

   }

  

   public int guessLetter(char c){

       int count = 0;

       guesses++;

       c = Character.toUpperCase(c);

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

       {

           if(Character.toUpperCase(secret_phrase[i]) == c && disguised_phrase[i] =='-' )

           {

               disguised_phrase[i] = c;

               count++;

           }

       }

      

       return count;

   }

  

   public String getDisguisedPhrase(){

       return new String(disguised_phrase);

   }

   public String getSecretPhase(){

       return new String(secret_phrase);

   }

  

   public void increaseJackpot(int amt){

       jackpot += amt;

   }

   public int getGuessCount(){

       return guesses + 1;

   }

  

   public boolean isFound(){

       if(getSecretPhase().equalsIgnoreCase(getDisguisedPhrase()))

           return true;

       else

           return false;

   }

   private void initialize(){

       secret_phrase = songs[random.nextInt(songs.length)].toUpperCase().toCharArray();

       disguised_phrase = new char[secret_phrase.length];

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

       {

           if(secret_phrase[i] == ' ')

               disguised_phrase[i] = ' ';

           else

               disguised_phrase[i] = '-';

       }

      

       for(int i = 0; i < 26; i++)

           already_guessed[i] = 0;

       jackpot = 0;

       guesses = 0;

       incorrect = 0;

   }

  

   private boolean isAlreadyGuessed(char ch)

   {

       ch = Character.toUpperCase(ch);

       if(already_guessed[ch-'A'] == 1)

           return true;

       else

           return false;

   }

   public void start(){

       Scanner keybd = new Scanner(System.in);

       String ans;

       while(true)

       {

           initialize();

          

           System.out.println("Welcome to the Guessing Game. The topic is song titles.");

           System.out.println("You have 6 guesses. Your puzzle has the following letters.");

           System.out.println(" " + getDisguisedPhrase() );

           for(int round = 1; round <= 6; round++)

           {  

               System.out.println(" Round " + round +":");

               int amt = spinWheel();

               System.out.println("After spinning the wheel, you got $" + amt +".");

               System.out.print("Please guess a letter: ");

               char ch = Character.toUpperCase(keybd.next().charAt(0));

               int count = guessLetter(ch);

               if( count == 0)

               {

                   if(isAlreadyGuessed(ch))

                   {

                       System.out.println("Too bad - you already guessed " + ch + " and there is no " + ch);

                   }

                   else

                   {

                       System.out.println("There is no " + ch);

                   }

                  

               }

               else

               {

                   System.out.println("There is/are " + count + "e");

               }

               already_guessed[ch-'A'] = 1;

               jackpot += count * amt;

               System.out.println(" " + getDisguisedPhrase() + " ");

              

               if(isFound())

               {

                   System.out.println("Great Guess! You win $" + jackpot);

                   break;

               }

              

               System.out.print(" Do you know the song? (y or n): ");

               ans = keybd.next();

               if(ans.equalsIgnoreCase("y"))

               {

                   System.out.print(" What is it: ");

                   keybd.nextLine(); //flush newline

                   ans = keybd.nextLine().trim();

                   if(ans.equalsIgnoreCase(getSecretPhase()))

                   {

                       System.out.println("Great guess! You win $" + jackpot + ".");

                   }

                   else

                   {

                       System.out.println("Too bad - wrong song! It is " + getSecretPhase() + ". You lost $" + jackpot +"! Game over.");

                   }

                   break;

               }

               else

               {

                   if(guesses == 6)

                   {

                       System.out.println("You did not guess ! It is " + getSecretPhase() +". You lost $" + jackpot +"! Game over.");

                       break;

                   }

                   else

                   {

                       System.out.println(" Your jackpot is $" + jackpot);

                       System.out.println("You have " + (6 - round) + " guesses left.");

                   }

               }

                  

           }

          

           System.out.println("Play again? (y/n) : ");

           ans = keybd.next();

           if(!ans.equalsIgnoreCase("y"))

               break;

       }

       System.out.println("Thanks for playing!");

   }

  

   public static void main(String[] args) {

       Game g = new Game();

       g.start();

   }

}

output

Welcome to the Guessing Game. The topic is song titles.

You have 6 guesses. Your puzzle has the following letters.

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

Round 1:

After spinning the wheel, you got $200.

Please guess a letter: y

There is/are 2e

Y-- ----- -- -Y ----

Do you know the song? (y or n): n

Your jackpot is $400

You have 5 guesses left.

Round 2:

After spinning the wheel, you got $200.

Please guess a letter: o

There is/are 1e

YO- ----- -- -Y ----

Do you know the song? (y or n): e

Your jackpot is $600

You have 4 guesses left.

Round 3:

After spinning the wheel, you got $200.

Please guess a letter: u

There is/are 2e

YOU ----- U- -Y ----

Do you know the song? (y or n): y

What is it: You light up my life

Great guess! You win $1000.

Play again? (y/n) :

y

Welcome to the Guessing Game. The topic is song titles.

You have 6 guesses. Your puzzle has the following letters.

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

Round 1:

After spinning the wheel, you got $500.

Please guess a letter: I

There is/are 1e

I ---- -- ---- ---- ----

Do you know the song? (y or n): a

Your jackpot is $500

You have 5 guesses left.

Round 2:

After spinning the wheel, you got $500.

Please guess a letter: a

There is/are 2e

I -A-- -- ---- ---- -A--

Do you know the song? (y or n): n

Your jackpot is $1500

You have 4 guesses left.

Round 3:

After spinning the wheel, you got $200.

Please guess a letter: h

There is/are 2e

I -A-- -- H--- ---- HA--

Do you know the song? (y or n): n

Your jackpot is $1900

You have 3 guesses left.

Round 4:

After spinning the wheel, you got $500.

Please guess a letter: t

There is/are 2e

I -A-T T- H--- ---- HA--

Do you know the song? (y or n): n

Your jackpot is $2900

You have 2 guesses left.

Round 5:

After spinning the wheel, you got $500.

Please guess a letter: o

There is/are 3e

I -A-T TO HO-- -O-- HA--

Do you know the song? (y or n): n

Your jackpot is $4400

You have 1 guesses left.

Round 6:

After spinning the wheel, you got $200.

Please guess a letter: d

There is/are 2e

I -A-T TO HO-D -O-- HA-D

Do you know the song? (y or n): n

You did not guess ! It is I WANT TO HOLD YOUR HAND. You lost $4800! Game over.

Play again? (y/n) :

n

Thanks for playing!

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