Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need it to be answered ASAP. This is a JAVA assignment, please followexactly what the question ask you to do. Thank you so much. You

Need it to be answered ASAP. This is a JAVA assignment, please followexactly what the question ask you to do. Thank you so much.

You are going to write a very simple text version of this game. There will only be one player and three dollar amounts ($200, $500 and $1000) 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.

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 The Game class will have the following methods: spinWheel( ) which returns a random int of 100, 200 or 500 guessLetter(c) guesses that character c (letter c) in the phrase and returns the number of times that letter is in the phrase. GetDisguisedPhrase( ) returns a String containing correctly guessed letters in the correct positions and unknown letters replaced with _. getSe cretPhrase( ) returns the secret phrase. increaseJackpot(int amt) which increases the jackpot by the amount that turn (number of times the guessed letter is in the phrase x the money amount from the spin) getGuessCount( ) returns the number of guesses made. isFound( ) returns true if the hidden phrase has been discovered. Appropriate constructor and get and set methods (and any others that make sense).

Implement the Game class. Next write a demo class that demonstrates the game. For this class, first create an array of song titles (these titles can be hardcoded as a String array). Select one song title at random from the array as the secret phrase. The following program shows you how to use java.util.Random to select a phrase at random from an array of song titles. import java.util.Scanner; import java.util.Random; public class RandomWord { public static void main(String[] args) { String[] songs = { "shake it off" , "satisfaction" , "mr jones" , "uptown funk" }; //note this is a very short list as an example Random rand = new Random(); int i = rand.nextInt(songs.length); System.out.println(songs[i]); } } Note: You can also use the Random class to determine the money value from the spin (200, 500, or 1000).

Heres how a sample run of what the program would look like: 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: e There is/are 1 e. _ _ _ _ _ E _ Do you know the song? (y or n): n Your jackpot is $200 You have 5 guesses left. Round 2: After spinning the wheel, you got $500. Please guess a letter: There is no a. _ _ _ _ _ E _ Do you know the song? (y or n): n Your jackpot is $200 You have 4 guesses left. Round 3: After spinning the wheel, you got $1000. Please guess a letter: s There is/are 1 s. _ _ _ _ _ E S Do you know the song? (y or n): n Your jackpot is $1200 You have 3 guesses left. Round 4: After spinning the wheel, you got $1000. Please guess a letter: Too bad you already guessed a and there is no a. _ _ _ _ _ E S Do you know the song? (y or n): n Your jackpot is $1200 You have 2 guesses left. Round 4: After spinning the wheel, you got $200. Please guess a letter: M There is/are 1 M. M _ _ _ _ E S Do you know the song? (y or n): What is it: MR JONES Great Guess! You win $1400! 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 $200. Please guess a letter: n There is/are 2 n. _ N _ N 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 $500. Please guess a letter: t There is/are 1 t. _ T N Do you know the song? (y or n): What is it: LOTOWN FUNK Too bad wrong song! It is UPTOWN FUNK. You lost $900! Game over. Play again (Y/N): N Thanks for playing!

I hope the answer can fit the sample output.

And that is what I get right now, hope it can make your work easier.

____________________Game Class____________________________

import java.util.Random; public class Game { char[] phrase=null; char[] disguised_phrase=null; int no_of_guesses=0; int curr_success_count=0; int letter_reveal_count=0; int no_of_incorrect_guesses=0; int jackpot_amount=0; boolean found_status=false; Random rand=new Random(); int jackpot[]={100,200,500}; char alpha_char; public Game(char[] secret_phrase,char[] disguised_phrase) { this.phrase=secret_phrase; this.disguised_phrase=disguised_phrase; } public void setSecretPhrase(char[] phrase) { this.phrase = phrase; } public char[] getDisguised_phrase() { return disguised_phrase; } public void setDisguised_phrase(char[] disguised_phrase) { this.disguised_phrase = disguised_phrase; } public int spinWheel() { return jackpot[rand.nextInt(jackpot.length)]; } public int guessLetter(char c) { int count=0; for(int i=0;i

} public void increaseJackpotAmount(int amt) { this.jackpot_amount+=(amt*curr_success_count); } public char[] getSecretPhrase() { return this.phrase; } public boolean isFound() { if(this.getGuessCount()-this.no_of_incorrect_guesses<=this.getGuessCount()&&this.letter_reveal_count==this.disguised_phrase.length) found_status=true; return this.found_status; } public int getGuessCount() { return this.no_of_guesses; } }

_____________________GuessGameDemo Class___________________________________

import java.util.Random; import java.util.Scanner; public class GuessGameDemo { public static void main(String[] args) { char repeat; String guess; String secretword; String[] songs = {"shake it off", "satisfaction", "mr jones", "uptown funk" }; Random rand = new Random(); do{ int m = rand.nextInt(songs.length); secretword = songs[m]; char[] secret_phrase = songs[m].toCharArray(); char[] disguised_phrase={'_','_','_','_','_','_','_','_','_','_','_','_','_','_'}; Scanner s=new Scanner(System.in); Game g=new Game(secret_phrase,disguised_phrase); System.out.println(" -------------Welcome to the Guessing game------------"); System.out.println(" ------------- topic is song titles------------ You have 6 guesses your puzzle has the following letters :"+new String(g.getDisguised_phrase())); for(int i=1;i<=6;i++) { g.no_of_guesses++; System.out.print(" -------------------------------------"); System.out.println(" ROUND "+i); int curr_spin=g.spinWheel(); System.out.println("After spinning the wheel,you got"+curr_spin); System.out.println(secret_phrase); System.out.println(" Please guess a letter : "); //char d=s.next().charAt(0); char c=s.next().charAt(0); int count=g.guessLetter(c); if(count>0) { System.out.println("there is/are "+count+" "+c); System.out.println(g.getDisguised_phrase()); g.increaseJackpotAmount(curr_spin); g.curr_success_count=count; } g.letter_reveal_count+=g.curr_success_count; if(count==0) { System.out.println("there is no "+c); System.out.println(g.getDisguised_phrase()); g.increaseJackpotAmount(curr_spin); System.out.print("Your jackpot is : "+g.jackpot_amount); } if(g.isFound()==true) { System.out.println("Guessed Successfully in "+g.getGuessCount()+" attempts....... The Song is :"+new String(g.getSecretPhrase())); System.out.println("you get: $"+g.jackpot_amount+" as your reward!"); break; }

g.curr_success_count=0; c='\0'; System.out.println("you get: "+g.letter_reveal_count); } s.nextLine(); System.out.println("Would you like to play again?"); System.out.print("Enter Y for yes or N for no: "); String input = s.nextLine(); repeat=input.charAt(0); } while(repeat == 'Y' || repeat == 'y'); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

1. Which is the most abundant gas presented in the atmosphere?

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago