Question: Word Game Problem: you are to write a java program allowing the user to play a word game. There should be two different lists of
Word Game Problem: you are to write a java program allowing the user to play a word game. There should be two different lists of words: a set of misspelled words and a set of words spelled correctly. Here are the steps to play the game: 1. Your program randomly selects a word from the list (it could be a word that is misspelled or a word that is spelled correctly. 2. The word will be displayed to the user 3. User needs to decide if the word is spelled correctly or not 4. If the users answer is correct then he/she will gain one point otherwise he/she will lose a point 5. Ask the user if he/she wants to play again 6. If the answer is no, display the score 7. If the answer is yes go to the step 1. How to write your program: 1. You can use arrays of strings to store the words. How many arrays do you need? 2. You need to have two files for the words: Misspelled words and correct words 3. Fill in you arrays by reading from the files 4. Use a variable to keep track of the score 5. The randomly selected word cannot be repeated. Therefore you need to keep track of the words already shown to the user. 6. Use the scanner class to interact with the user. 7. Use the Random class to generate random numbers to pick a word from the list. How many random numbers do you need? You need two random numbers but why? 8. Use while loop to repeat the game as long as the user is interested. Requirements: 1. Write a method for displaying the description of your program 2. Write a method for filling in the array from the files 3. Write a method called play 4. Write the algorithm for this program before start coding 5. Provide a description of your program 6. You must use methods in your program. 7. Appropriate identifier naming 8. Comments 9. Proper indentation 10. Follow the naming conventions
import java.io.*; import java.util.*; public class WordGameShell { public static void main(String[] args) throws FileNotFoundException { //declare two arrays of String with the size 20 //call the method description //call the method fillArray //call the method play } public static void description() { } /*this method reads the file and fills in the array*/ public static void fillArray(String[] correct, String[] incorrect) throws FileNotFoundException { //create two file objects with the .txt file that you have //use scanner object to fill in the arrays } public static void play(String[] correct, String[] incorrect) { Scanner keyBoard = new Scanner(System.in); int point = 0; int correctAnswer = 0; String answer; int randnum = 0; int list = 0; //chooses if the word will be from the correct or incorrect list String replay = "y"; int replayCorrect = 0; int timesplayed = 0; String repeat = "y"; Random random = new Random(); while(repeat.equalsIgnoreCase("y")) { // timesplayed = 0; while(replay.equals("y")&& timesplayed < 5) { timesplayed++; //generate a random number 0 or 1 //if the random number is zero { //generate a random number 0-19 //as long as the array at the given index is null { //generate a random number 0-19 } //display the word at the index from the correct list //ask the user if it is spelled correctly //store null at the given index to remove the word from the lits //update the points earned based on the user's answer } // else { //same as the if part except that a word from the incorrect list will be chosen } } //if the user played maximum number of times //display the appropriate messages //ask the user if she/he wants to play again //reset all the needed variables } } } /*Sample output The word is: Token mis-spelled? y/n :y Incorrect! The word is: File mis-spelled? y/n :y Incorrect! Here is the word: Ermahgerd Mis-speeled? y/n :y Correct! The word is: Throws mis-spelled? y/n :y Incorrect! The word is: Preceding mis-spelled? y/n :y Incorrect! You've played 5 times, give someone else a turn! You got 0 points. Would you like to play again? y/n fdf Please enter "n" or "y". fddf Please enter "n" or "y". y Here is the word: Werd Mis-speeled? y/n :y Correct! The word is: Numbers mis-spelled? y/n :n Correct! Here is the word: Werld Mis-speeled? y/n :y Correct! Here is the word: Amurica Mis-speeled? y/n :n Incorrect!! Here is the word: Unicron Mis-speeled? y/n :n Incorrect!! You've played 5 times, give someone else a turn! You got 1 points. Would you like to play again? y/n yes Please enter "n" or "y". y Here is the word: Incorect Mis-speeled? y/n :y Correct! The word is: Program mis-spelled? y/n :n Correct! Here is the word: Progrems Mis-speeled? y/n :y Correct! Here is the word: Fiyuhl Mis-speeled? y/n :n Incorrect!! The word is: Exception mis-spelled? y/n :y Incorrect! You've played 5 times, give someone else a turn! You got 1 points. Would you like to play again? y/n n ----jGRASP: operation complete. */ Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
