Question: Design and implement a word unscrambler game in Java. Instructions Your program should read in a random word from a file calledwords.txt (note the lack

Design and implement a word unscrambler game in Java.


Instructions
Your program should read in a random word from a file calledwords.txt (note the lack of capitalization) that you provide. Thefile should contain:

One word per line

At least 10 different words

Each word should have at least 5 letters

Words should have variable lengths


To read a random word you can generate a random number between 1and the number of lines, and skip n-1 lines before reading theword. Scramble the word by swapping random pairs of letters arandom number of times (mandatory use of a loop). Display thescrambled word with character indices on top. Offer the user a menuwith the following choices:

Enter 1 to swap a pair of letters


If this option is selected, prompt the user to enter two indicesand swap the letters. A space should separate the two indices.Print an error message if the indices are invalid. If the word isunscrambled successfully, print a congratulatory message containingthe word and the number of steps it took to unscramble. Otherwise,display the new word and offer the menu again.

Enter 2 to solve


If this option is selected, print the unscrambled word andquit.

Enter 3 to quit


If this option is selected, quit.


Example run:

---------

0123456

rpocjet

---------

Enter 1 to swap letters.

Enter 2 to solve.

Enter 3 to quit.

1

Enter the indices separated by spaces

0 1

---------

0123456

procjet

---------

Enter 1 to swap letters.

Enter 2 to solve.

Enter 3 to quit.

1

Enter the indices separated by spaces

3 4

---------

0123456

projcet

---------

Enter 1 to swap letters.

Enter 2 to solve.

Enter 3 to quit.

1

Enter the indices separated by spaces

4 5

Congratulations! You unscrambled the word project in 3 steps.

Step by Step Solution

3.43 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Here is an example implementation of a word unscrambler game in Java import javaio import javautil public class WordUnscrambler private static final String WORDSFILE wordstxt private static final int ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!