You are to write a computer game! Hangman, to be specific. It will be run as follows:

$> java Hangman Dictionary.txt 35

or

$> java Hangman Dictionary.txt 13 --easy

The first command line argument is always the filename for a dictionary, which consists of one word (and no whitespace) on each line.

The second command line argument is a number, specifying which word to use from the dictionary. This could be any integer 0 or greater. if the number is larger than the number of words in the dictionary file, the program should print "ERROR: index greater than dictionary length - 1" and quit. The third, optional command line argument ("--easy") tells the game that we are in easy mode. In this mode, the letters RSTLNE are automatically guessed for "free" before the game even begins.

Once the program starts, the following interaction will repeat for the length of the word + 7 times:

  • Print the game board. Print a _ for each unguessed letter, or the letter in the correct position for each guessed letter.
  • Print the word "WRONG: " followed by each letter that was an incorrect guess.
  • Print "Guess N/M: " where N is the current guess number and M is the total number of allowable guesses.
  • Read a letter from the user.
    • If the letter is in the word, print a congratulatory message and make sure it gets printed the next time the loop repeats.
    • If the user just won, print the message "Congratulations, you won!"
    • If the letter is NOT in the word, print a sad message and make sure it gets printed in the WRONG list the next time the loop repeats.
    • If the user just lost, print the message "Aww, you lost!"
    • If the user already guessed the letter, print a message indicating as such and repeat the loop. That is, if this was the 4th guess, the next guess should be the 4th guess, too.

After the loop completes, print the word regardless.

You may assume the presence of the FileRead class from the lab "Files Abridged" when writing this project.

The program should NOT be case sensitive. Our grading software will enter single upper-case letters, separated by newlines, but the examples use lower-case letters.

Example interactions:

$ java Hangman Dictionary.txt 3 --easy
___L_T_
WRONG: RSNE
GUESS 1/14: A
Great guess!
A__L_T_
WRONG: RSNE
GUESS 2/14: I
Great guess!
A_ILIT_
WRONG: RSNE
GUESS 3/14: B
Great guess!
ABILIT_
WRONG: RSNE
GUESS 4/14: Y
Great guess!
Congratulations, you won!
Solution: ABILITY

$ java Hangman Dictionary.txt 4 --easy
____T
WRONG: RSLNE
GUESS 1/12: z
WRONG!
____T
WRONG: RSLNEZ
GUESS 2/12: x
WRONG!
____T
WRONG: RSLNEZX
GUESS 3/12: c
WRONG!
____T
WRONG: RSLNEZXC
GUESS 4/12: v
WRONG!
____T
WRONG: RSLNEZXCV
GUESS 5/12: b
Great guess!
_B__T
WRONG: RSLNEZXCV
GUESS 6/12: n
WRONG!
_B__T
WRONG: RSLNEZXCVN
GUESS 7/12: m
WRONG!
_B__T
WRONG: RSLNEZXCVNM
GUESS 8/12: q
WRONG!
_B__T
WRONG: RSLNEZXCVNMQ
GUESS 9/12: w
WRONG!
_B__T
WRONG: RSLNEZXCVNMQW
GUESS 10/12: e
WRONG!
_B__T
WRONG: RSLNEZXCVNMQWE
GUESS 11/12: r
WRONG!
_B__T
WRONG: RSLNEZXCVNMQWER
GUESS 12/12: a
Great guess!
Aww, you lost!
Solution: ABOUT

$ java Hangman Dictionary.txt 2
____
WRONG:
GUESS 1/11: a
Great guess!
A___
WRONG:
GUESS 2/11: b
Great guess!
AB__
WRONG:
GUESS 3/11: l
Great guess!
ABL_
WRONG:
GUESS 4/11: l
Already guessed that letter.
ABL_
WRONG:
GUESS 4/11: t
WRONG!
ABL_
WRONG: T
GUESS 5/11: e
Great guess!
Congratulations, you won!
Solution: ABLE

$ java Hangman Dictionary.txt 5
_____
WRONG:
GUESS 1/12: q
WRONG!
_____
WRONG: Q
GUESS 2/12: w
WRONG!
_____
WRONG: QW
GUESS 3/12: e
Great guess!
____E
WRONG: QW
GUESS 4/12: r
WRONG!
____E
WRONG: QWR
GUESS 5/12: r
Already guessed that letter.
____E
WRONG: QWR
GUESS 5/12: t
WRONG!
____E
WRONG: QWRT
GUESS 6/12: y
WRONG!
____E
WRONG: QWRTY
GUESS 7/12: u
WRONG!
____E
WRONG: QWRTYU
GUESS 8/12: i
WRONG!
____E
WRONG: QWRTYUI
GUESS 9/12: o
Great guess!
__O_E
WRONG: QWRTYUI
GUESS 10/12: p
WRONG!
__O_E
WRONG: QWRTYUIP
GUESS 11/12: a
Great guess!
A_O_E
WRONG: QWRTYUIP
GUESS 12/12: s
WRONG!
Aww, you lost!
Solution: ABOVE

This is your dictionary words

abandon
abandoned
able
ability
about
above
abroad
absence
absent
absolute
absolutely
absorb
abuse
abuse
academic
accent
accept
acceptable
access
accident
Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.