Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

USE JAVA make a game call Wordle. Playing a game of wordle can be broken down into these steps: 1. The computer obtains a list

USE JAVA make a game call Wordle.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Playing a game of wordle can be broken down into these steps: 1. The computer obtains a list of possible words 2. The computer selects one word as the "secret" which the player will try to guess 3. The player guesses a word 4. The computer generates a hint about which letters are correct/incorrect. 5. The hint is communicated to the player. 6. Guessing continues until the player is out of turns or wins the game. The game is implemented in three classes: \%ord1e, Hint, and \%ord1eGame. The word1e class is responsible for items (1) and (2) above. Both the word1e class and the Hint class are responsible for item (4). The Word1e class must be part of providing a hint to the player since the wordle class knows what the secret word is. However, the logic for how to construct the hint itself, and the data associated with the details of the hint are encapsulated by the Hint class, so the wordle class acts mainly as a middle-man. The wordlegame class contains the logic for interacting between the computer and the player. That is, it is a user of the wordle and Hint classes. Specifically, the "ordleg ame starts steps (1) and (2) off by creating the word1e object instance. The word1eGame allows a player to guess a word (step 3) by reading input from the keyboard, and then sends that to the computer (i.e., the \%ord1e object instance) to obtain a hint, which is then printed for the user (step 5). This "game loop" continues until no more guesses remain, or the game is won (step 6). Implementation All coding takes place in the file wordee. java. You should look through all the code and generally l've tried to order the parts so that easier items are implemented first. Without a doubt, the most complex code live in the Hint constructor. Here, you'll be constructing a Hint to the puzzle. Of course constructing a Hint requires knowing what the secret word is as well as what the guess was. Then you'll need to figure out what letters are correctly placed, what letters are in the secret word, but incorrectly placed, and what letters aren't in the secret word at all. Read the comments for the constructor for more details. I suggest you implement this with a series of stages. First determining which characters are correctly placed then checking which are incorrectly placed, and finally determining which are not in the puzzle. Each stage will require some looping. Further there are a number of ways to create the Strings that will eventually become hint's instance variables. Here are some options: - Build Strings by concatenating smaller Strings with the + operator. - Build Strings from char arrays. - Build Strings using the StringBuilder class. At the top of the Hint constructor, you should provide a comment that provides reasoning/justification for the method you've used to build the Strings each Hint instance uses. You may use any of *** * - Part 1: Implement this constructor. * Load known words from the array that is supplied. It's ok if the * array contains duplicates, but the constructor should verify * that all loaded strings are the same length and are lowercase. * * aparam words - an array of words to load */ 1 usage public Wordle(String[] words) \{ \} I/ Todo: implement this nousages public int number0fknownWords() { return knownWords. size(); } * Part 2: Implement this method. - * Load words from a file. Each line of the file contains a word followed by one or more spaces followed * by a number whose value is higher for words that are more 'frequently occurring' than others. * Loaded words should have a frequency value in the range [minfreg, maxfreq]. However, at times, these * Limits should be ignored (see comments below). Note that the words in the file may be many lengths * (e.g., 3-10 characters). Only words of the specified length should be loaded. * Hint: use a Scanner instance to read in the file and look for the next String or Long value. * the following pattern will be useful ;) * Scanner scan = new Scanner(new File(filenm)); * The line above creates a Scanner from a File with the filename stored in the variable filenm * Use the scanner's . hasNext() method to test if there are more lines to read. * Use the scanner's . next() method to grab the next String token (word). * The scanner's . nextlong() method will grab the next token as a number (use this to read the frequency). * For each line, you will want to call scan.next() and scan.nextlong() to read the data * identifying a word and its relative frequency. * Words of the specified length should be added into the knownWords list if their frequencies * are the in the range specified. * Hint: somewhere around 10-20 lines is probably appropriate here unless you have a lot of comments * Qaparam filenm - the file name to load from * eparam length - the length of words we want to load (e.g., 5 to load 5 character words) * aparam minfreg - the minimum allowable frequency for a loaded word * Qparam maxfreg - the maximum allowable frequenct for a loaded word; indicates no maximum */ 1 usage public void loadWords(String filenm, int length, long minfreg, long maxfreg) throws I0Exception \{ // TODO: implement this return; /** * Part 3: Implement this method. * Obtain a list of known words. This method creates a new copy of the known words list. * Here, you simply need to copy the knownWords list and return that copy. * * areturn a new copy of list of known words. */ no usages public Arraylist getknownWords() \{ // Todo: implement this peturn null

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

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

Finance The Role Of Data Analytics In Manda Due Diligence

Authors: Ps Publishing

1st Edition

B0CR6SKTQG, 979-8873324675

More Books

Students also viewed these Databases questions