Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

chooseWord method (20 points) This method randomly chooses a word. The method should read in words from a file (such as words.txt, provided) and

image text in transcribedimage text in transcribed

chooseWord method (20 points) This method randomly chooses a word. The method should read in words from a file (such as words.txt, provided) and randomly choose a word. The method should also provide code to account for a missing file. In this case, the outcomeText should display an error message (such as "Error: No dictionary."). The guessField should then be disabled because the game cannot be played. The program should not crash or throw other exceptions. Hint for testing: Print out the randomly selected word you are trying to guess. This makes for much easier testing! handleGuessField method (50 points) This method responds to the user guess (typed into the guessField). This is basically the method that makes the game run! In this method, you should read in the user's guess and check if it is valid. If it's not valid, update the displays. If the guess is valid, you should check if the user has guessed the letter already. If they have, update the displays. If it's a new guess, check if it is right or wrong and update the displays. Then also check if the game is over (either the user guessed the word and won or reached the maximum wrong guesses and lost). For full credit: add additional helper methods. Do not have the entire game logic in the handleGuessField method. Some examples of helpful methods might be isGuessValid, updateDisplays, getDisplayVersion OfSWord, etc. create whatever instance data variables you need to keep track of things. Some examples might be a list that keeps track of guessed characters, an array that keeps track of whether each character in the word has been guessed, the number of wrong guesses, etc. reduce duplicated code You can add code to the start() method to initialize variables and/or invoke helper methods. I strongly recommend getting the game working before moving on to Part II. I strongly recommend getting the game working before moving on to Part II. Part II: Exception Handling (30 points) Add exception handling to cover three erroneous occurrences. Note: I realize you could write a working game that accounts for these situations without using exception handling. But, for this project, you are required to use exception handling. For all three situations, create your own exception type(s) to represent the situation. When the situation occurs, throw an object of the type you just created. The program should catch the exception(s) and update the displays. . The user continues to guess after invalid guesses. Invalid guesses does not count against the user's wrong guess count. Erroneous situations: 1. The user enters an empty guess 2. The user enters a guess that is longer than one character (like aa or zb) 3. The user enters a guess that is not a letter (like + or $) Hint: check out the Character class for help with detecting this situation! Your program method should not terminate or crash because of any of these thrown exceptions. All thrown exceptions should be caught and handled and the game should continue. Extra Credit: 15 points Allow the user to play multiple games. Add a "play again" button that is only visible when the game is over. Choose a new random word for each game. Sample Program and Project Files Below is a sample program you can run. For this program, the game only chooses between three words, to make it easier for you to guess! The words are apple, banana, and pear.

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions