Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

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 ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Building Java Programs A Back To Basics Approach

Authors: Stuart Reges, Marty Stepp

5th Edition

013547194X, 978-0135471944

More Books

Students also viewed these Programming questions

Question

What does the term homoscedasticity mean?

Answered: 1 week ago

Question

What is the output of the following loop? for (int i = 1; i

Answered: 1 week ago

Question

4.8 Describe ways of understanding and treating PTSD.

Answered: 1 week ago