Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The goal in our Word Mastermind program is to guess a four letter word. A clue will contain an 'O' for each correct letter you
The goal in our Word Mastermind program is to guess a four letter word. A clue will contain an 'O' for each correct letter you guessed in the correct position and an 'X' for each correct letter you guess in the wrong position. If the guessed letter is incorrect, the dash character will be used '-'.
Here is a sample run of the program:
I'm thinking of a 4 letter word. I will give you clues: An "O" means you guessed the correct letter in the correct position. An "X" means you guessed the correct letter but in the wrong position. Guess my word. pile ---- rave X--- morn -OX- hour -OOO your OOOO You guessed it in 5 tries! Do you want to play again?
SPECIFICATIONS:
- You should have 15 secret words to randomly choose from.
- Use Stringbuilder class. You can find information about this class using the Java API
- See: https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/StringBuilder.html (Links to an external site.)
- This class allows you to create and modify Strings (i.e. get and change a character in the string)
- Guesses given in uppercase should have the same effect as the lowercase equivalent
- If the user gives a character other than a letter, an error message should be printed. This does not count towards a wrong guess.
- User can have 7 wrong guesses before the game is over.
- If the user guesses all the letters, they win.
- Ask the user to play again.
- You may also need code from the API's Character class. https://docs.oracle.com/en/java/javase/13/docs/api/java.base/java/lang/Character.htm
STARTER CODE:
/** * * @author Student Name * @version 1.0 * @since -DATE FINISHED- * WordMastermind.java * * This program allows a user to play Mastermind with the computer. * --EXPLAIN THE RULES-- * */ import java.util.*; import java.lang.*; public class WordMastermind { //This is an array of Strings static String wordList[] = {"your","time","jedi", "skip"}; // add more to this list by adding more String Literals separated by commas /** * Entry point of the program * @param args input arguments */ public static void main(String[] args) { // This code snippet just shows you how to use Stringbuilder. // Change the code as you see fit. String secret = wordList[0]; // picks "your" as the word to be guessed StringBuilder currentResult = new StringBuilder(secret.length()); System.out.println(secret); currentResult.append("----"); System.out.println(currentResult); currentResult.setCharAt(0,'X'); System.out.println(currentGuess); } }
HINTS:
- Check out the Java API of the following classes:
StringBuilder, Character, String
- Compare the guess and the secret two times.
- First round, check if a "guess" character matches a "secret" character exactly.
- Mark your O's
- Second, check if a remaining "guess" character is located in the remaining parts of the "secret" word.
- Mark your X's
- First round, check if a "guess" character matches a "secret" character exactly.
- NOTE:
- If there are duplicate letters in the guess, they cannot all be awarded an X or an O's unless they correspond to the same number of duplicate letters in the hidden code. For example, if the hidden code is [cart] and the player guesses [cccc], the program will award [O---] as a response clue. It will not give [OXXX].
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started