Question: Objective: Develop a Java Hangman game using the class MyArrayList. The program should read a list of words from a text file, sort the words
Objective:
Develop a Java Hangman game using the class MyArrayList. The program should read a list of words from a text file, sort the words alphabetically, and then allow the user to play the game with one of the words chosen at random.
Instructions:
Use the provided text file named wordstxt
Use the provided MyArrayListHM class to implement the generic MyArrayList functionalities.
Implement the Hangman game logic using the MyHangman class.
Write the methods in the MyHangman class:
Write the method loadWords to read the words from the wordstxt file, store them in the words arraylist and display the words. Use the sortlist method of the MyArrayListHM class to sort the list and display the sorted list of words.
Write the method startNewGame to initialize a new game of Hangman. This method should randomly select a word from the list of words, set up the secret word and guessed word arrays, and initialize the number of guesses left.
Write the method playGame that handles user input, updates the game state, and provides feedback to the player. The method manages the gameplay loop to continue the game as long as there are guesses left and the word has not been completely guessed. Hint Use the updateGuessedWord and isWordGuessed methods discussed below
Write a method updateGuessedWord in the MyHangman class. The method receives the correct guessed letter as parameter and updates the guessed word with the correct guessed letter. Hint Use the remove and the add methods of the MyArrayListHM class to replace the character with the correct guessed letter
Write a method isWordGuessed in the MyArrayListHM class to check if the entire word has been correctly guessed by the player. The method should return a boolean value indicating whether the word has been correctly guessed. Hint Use the contains method of the MyArrayListHM class to check if the guessed word still contains an underscore character
Example Output:
The words: Apple Bread, Chair, Earth, House, Italy, Juice, Knife, Lemon, Mouse, Snake, Table, Venus, Zebra, Eagle, Horse, Onion, Pizza, Robin, Tiger
The sorted words: Apple Bread, Chair, Eagle, Earth, Horse, House, Italy, Juice, Knife, Lemon, Mouse, Onion, Pizza, Robin, Snake, Table, Tiger, Venus, Zebra
Welcome to Hangman!
Guesses left:
Enter a letter: r
Incorrect guess.
Guessed word: E
Guesses left:
Enter a letter: o
Correct guess!
Guessed word: E O
Guesses left:
Enter a letter: s
Incorrect guess.
Guessed word: E O
Guesses left:
Enter a letter: p
Incorrect guess.
Guessed word: E O
Guesses left:
Enter a letter: m
Correct guess!
Guessed word: E M O
Guesses left:
Enter a letter: l
Correct guess!
Guessed word: L E M O
Guesses left:
Enter a letter: n
Correct guess!
Congratulations! You guessed the word: L E M O N
Instructions to Complete the Assignment:
Use the two Java files: MyArrayListHMjava and MyHangmanjavaand complete the code.
I have no idea where to begin.provided code:
public class MyArrayListHM
private int size; Number of elements in the list
private E data;
private int MAXELEMENTS ;
Create an empty list
public MyArrayListHM
data Enew ObjectMAXELEMENTS; cannot create array of generics
size ; Number of elements in the list
public boolean isFull
if size size
throw new IndexOutOfBoundsException
Index: index Size: size;
Move the elements to the right after the specified index
for int i size ; i index; i
datai datai;
Insert new element to dataindex
dataindex e;
Increase size by
size;
public boolean containsObject e
for int i ; i size; i
if eequalsdatai return true;
return false;
public E getint index
if index index size
throw new IndexOutOfBoundsException
Index: index Size: size;
return dataindex;
public E removeint index
if index index size
throw new IndexOutOfBoundsException
Index: index Size: size;
E e dataindex;
Shift data to the left
for int j index; j size ; j
dataj dataj ;
datasize null; This element is now null
Decrement size
size;
return e;
public void clear
size ;
public String toString
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
