Question
PLEASE READ THE INSTRUCTION BEFORE STARTING THERE IS A SHELL AT THE BOTTOM THAT MUST BE FOLLOWED Word Game Problem: you are to write a
PLEASE READ THE INSTRUCTION BEFORE STARTING
THERE IS A SHELL AT THE BOTTOM THAT MUST BE FOLLOWED
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:
Your program randomly selects a word from the list (it could be a word that is misspelled or a word that is spelled correctly.
The word will be displayed to the user
User needs to decide if the word is spelled correctly or not
If the users answer is correct then he/she will gain one point otherwise he/she will lose a point
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:
You can use arrays of strings to store the words. How many arrays do you need?
You need to have two files for the words: Misspelled words and correct words
Fill in you arrays by reading from the files
Use a variable to keep track of the score
The randomly selected word cannot be repeated. Therefore you need to keep track of the words already shown to the user.
Use the scanner class to interact with the user.
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?
Use while loop to repeat the game as long as the user is interested.
Requirements:
Write a method for displaying the description of your program
Write a method for filling in the array from the files
Write a method called play
Write the algorithm for this program before start coding
Provide a description of your program 6. You must use methods in your program.
Appropriate identifier naming
Comments
Proper indentation
Follow the naming conventions
-----------------------------------------------------------------------------------------------------------------------------------------------------------
SHELL:
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started