Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Creating the Wordle Class: 1. In the Sandbox, create a new console program. Then create a class called Wordle 2. Create your attributes: a.

image text in transcribed imageimageimage

Creating the Wordle Class: 1. In the Sandbox, create a new console program. Then create a class called Wordle 2. Create your attributes: a. a static final class variable called wordPool that is an array of 5 letter strings. This will be your word pool and should have a minimum of 20 words. You can have as many as you wish. All words should be upper case. Use an initializer list for this attribute when you create the class variable. You will NOT initialize this in the constructor. b. Two static class variables for a Random and a Scanner object, also initialized when declared, and not in the constructor. C. an instance variable called todaysWordle that represents the "Wordle of the Day" the user will be guessing 3. d. an instance variable called alphabet that is an array of characters that represents the possible letters in the alphabet. Create your constructors: a. One constructor for the class that takes one integer parameter. This will be used to test your program using a specific word of your choice. Be sure to initialize the instance vars: i. Initialize todaysWordle to the String from the wordPool using the parameter as the index. If the parameter is out of range, use the first word in wordPool ii. Initialize alphabet to each letter in the alphabet, all lower case (see class discussion for how to do this with letters). b. A second constructor that takes no parameters. This will be the one used when you actually play the game. Hint: instead of initializing the two instance variables, you can pass a random integer as the parameter to the first constructor. This is a bit tricky, so please see me if you want to try this but have questions. 4. You will not create a getter or setter methods for this class, since everything will happen in the play method. 5. Create a method called play. This is where the real work of your game will happen. There will be more details below about what will go into the play method. You will also be creating several private helper methods that are called from this method. 6. Create a main method in Wordle. This will be how you start the game. In the main method, you should have one line of code that creates a Wordle game, and a second line of code to call the play method. While you are creating and testing the game, you should pick one specific word to test your code with, like this: System.out.println("This is a practice version of the game"); Wordle practice = new Wordle(5); practice.play(); Once you are satisfied your code is working, you will add the actual game using the constructor that randomly picks a word, like this: System.out.println("Let's play the real game now!"); Wordle dailyGame = new Wordle(); dailyGame.play(); Method play() Instructions: This method contains the game play code. It will have several helper methods (all private) as specified below. Choose good names for your helper methods. 1. The play() method will have a main loop that keeps going if the user has not guessed the word yet and they have more tries left. They have 6 tries to guess the word. 2. You will need to keep track of the number of guesses the user has made and later print this with the results of their guess (see example output below). 3. Prompt the user for a 5 letter word. You may assume they enter a 5 letter word (though you can add additional code to check if you wish). Remove any leading or trailing whitespace, convert the word to all uppercase letters, then return it. This task must be done in a private method that has a return type of String and no parameter. 4. Check to see if each character in the user's guess is in the "Wordle of the Day". This task must be done in a private method that takes the user's guess (a String) as a parameter and returns the solution as another String. Proceed as follows: a. In this private method, create a local char array variable called guess. Then use a loop (NOT a method call) to initialize it using the String parameter. You are to use a loop because we are in the array unit and I want to see you initialize arrays with loops > b. Also in this private method, create a local char array variable called solution. This will hold the analyzed word, and it's the one you will return from the method when you're done. c. Create a loop to check each letter in guess. There are three possible outcomes: i. The character is in todaysWordle and it is in the same position. In this case, you should add that character to solution in the same position, keeping the character as upper case. Upper case letters are equivalent to a "green" letter in the game (correct letter, correct position). ii. The character is in todaysWordle but NOT in the correct position. In this case, you should add the letter to solution as a lowercase letter, in the same position. You will also change the same letter in the alphabet array to uppercase. Lowercase letters are equivalent to a "yellow" letter in the game (correct letter, wrong position). iii. The character is NOT in the todays Wordle in any position. In this case, you should change the letter in solution array to a dash ("-") and in the alphabet array to a blank. d. Once you have finished, and have the completed solution array, you will turn it into a String object and return it from this private method. 5. After the analysis is done, display the number of guesses made so far, the solution, and the updated alphabet array to the user. This task must be done in a private method that takes the number of guesses and the solution as parameters, but it should nor return anything (void type). 6. One you have finished with the game (ie, the loop has ended), print either a congratulatory message or a message telling them they are out of tries, as appropriate. If they are out of tries, print the word. 7. Your main method may have practice and full game code, as long as you also print messages specifying which one (see example below). Example Output: This is a practice version of the game #0: BESTS Letters left: abcdefghijklmnopqrstuvwxyz Enter your 5 letter guess: train #1: Letters left: bcdefgh jklm opq stuvwxyz Enter your 5 letter guess: bouts #2: BTS Letters left: Bcdefgh jklm pq ST vwxyz Enter your 5 letter guess: beets #3: BEETS Letters left: BodEfghjklm pq ST vwxyz Enter your 5 letter guess: belts #4: BE-TS Letters left: BodEfghjk m pq ST vwxyz Enter your 5 letter guess: bests #5: BESTS Letters left: BodEfgh jk m pq ST vwxyz Congratulations! You guessed the word in 5 tries! Let's play the real game now! Enter your 5 letter guess: steam #1: ea Letters left: Abcdefghijkl nopqr uvwxyz Enter your 5 letter guess: gavel #2: -ave- Letters left: AbcdEf hijk nopqr uvwxyz Enter your 5 letter guess: haven #3: Have Letters left: AbcdEf Hijk Enter your 5 letter guess: heave #4: HEAVE Letters left: AbcdEf Hijk Enter your 5 letter guess: heave #5: HEAVe Letters left: AbcdEf Hijk Enter your 5 letter guess: heavy opqr uvwxyz opqr uvwxyz opqz uvwxyz opqr UVWXYZ #6: HEAVY Letters left: AbcdEf Hijk. Congratulations! You guessed the word in 6 tries!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Here is a simplified implementation of the Wordle class based on your requirements This code includes the requested constructors play method and the p... 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

Step: 3

blur-text-image

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

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions

Question

Describe diversitybased conflict.

Answered: 1 week ago