Creating the Wordle Class: 1. In the Sandbox, create a new console program. Then create a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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! 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!
Expert Answer:
Answer rating: 100% (QA)
Here is a simplified implementation of the Wordle class based on your requirements This code includes the requested constructors play method and the p... View the full answer
Related Book For
Java How To Program Late Objects Version
ISBN: 9780136123712
8th Edition
Authors: Paul Deitel, Deitel & Associates
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
Prepare adjusting journal entries, as needed, considering the account balances excerpted from the unadjusted trial balance and the adjustment data. A. amount due for employee salaries, $4,800 B....
-
The balance sheet of Spottified Corp. recently included: Investments in significantly influenced and other companies $2,500,000 Spottified Corp. included its short-term investments among the current...
-
For each of the situations, set up the rejection region: a. H0: 1 = 2 versus Ha: 1 2 with n1 = 12, n2 = 15, and = .05 b. H0: 1 2 + 3 versus Ha: 1 > 2 + 3 with n1 = n2 = 25 and = .01 c. H0: 1 2 ...
-
A burst of compressed air pushes a pellet out of a blowpipe. The force exerted by the air on the pellet is given by \(F(t)=F_{0} e^{-t / \tau}\), where \(\tau\) is called a time constant because it...
-
Kunkel Company makes two products and uses a traditional costing system in which a single plantwide predetermined overhead rate is computed based on direct labor-hours. Data for the two products for...
-
How does smart home assistant product align with broader trends or societal needs, reflecting your understanding of market dynamics and consumer behavior?
-
The client's husband attacked her so severely that she was hospitalized. They are now separated, and the client wants to sue her husband. The husband still lives on the military base where they lived...
-
You want to visit your friend in Chicago and decide to take the train. Unfortunately, you are late getting to the train station. You are running as fast as you can, but the train begins to pull out...
-
What would be a perfect sample to describe the constitutional law, and all the other sources of law ?
-
Evaluate the effectiveness of different communication channels in facilitating knowledge sharing and innovation in a decentralized organization.
-
How do advances in genomic technologies, such as whole-genome sequencing, genome-wide genotyping arrays, and next-generation sequencing methods, facilitate the characterization of individual...
-
How is the limiting charge calculated for NonPAR providers? Explain.
-
Ecker Inc. applies overhead based on machine hours. During the year the company estimated that they would have total estimated overhead costs of $400,000 and total estimated machine hours of...
-
How does opportunity cost affect your decision to pursue employment in the future?
-
$10,000 was borrowed at 3.5% on July 17. The borrower repaid $5000 on August 12, and $2000 on September 18. What final payment is required on November 12 to fully repay the loan?
-
Modify Exercise 4.15 to combine your code from the four separate triangles of asterisks such that all four patterns print side by side. Make clever use of nested for loops. Exercise 4.15 Write an...
-
Create an app that scrolls a series of images across a marquee screen on a Canvas.
-
As presented in the text, linked lists must be searched sequentially. For large lists, this can result in poor performance. A common technique for improving list-searching performance is to create...
-
______________ occur(s) when the speaker should pause but instead fills the silence (umm, ahh).
-
Identify an election (federal, state, or local) for which a debate was broadcast. Analyze how the different speakers were able to adapt their messages based on the moderators questions and their...
-
___________ refers to your credibility as a presenter as well as the credibility of the information delivered in your presentation.
Study smarter with the SolutionInn App