Jump to content
Sal's RuneScape Forum
Sign in to follow this  

Word Unscrambler Game...Figuring Out The Statements

Recommended Posts

Posted (edited)

Hey everyone! So I am very new to the Java language, and I am trying to figure out how to design and implement a word unscrambler game that reads a word from a text file, scrambles it, and allows the user to switch the character indexes as they please...Here is my code.

01 import java.util.*
02 import java.io.*
04 public class Unscrambler
05 {
06     //-----------------------------------------------------------------------------------------
07     // This program reads a random word from a file created separately called words.txt that
08     // has been provided. The program then scrambles the word by swapping random letters a
09     // random number of times. The scrambled word is displayed with character indexes on top.
10     // The user selects 1 to swap a pair of letters, 2 to print the word unscrambled and quit,
11     // and 3 to simply quit. When the word is scrambled correctly, the computer congratulates
12     // the user, repeats the unscrambled word, and the number of steps it took to solve. An
13     // error message appears if invalid indexes are input by the user.
14     //-----------------------------------------------------------------------------------------
16     public static void main (String[] args) throws IOException
17     {
18         //Setting Up Variables and Scanners wordsia to read from User and words.txt
19         String words;
20         Scanner fileScan, wordsScan, optionScan;
21         int option;
22         boolean done = false;
23         Random generator = new Random();
25         fileScan = new Scanner (new File("words.txt"));
26         words = filescan.nextLine(generator.nextInt(22);
27         optionScan = new Scanner (System.in);
29         while (!done)
30         {
31             //Menu
32             System.out.prinln ("Welcome Computational Unscrambling!");
33             //read from User
34             option = optionScan.nextInt(3) + 1;
36             if (option == 1)
37             {
38                 //Allow user to switch letters between index;
39                 //If User unscrambles word, done == true;
40             }
41             else
42             {
43                 if (option == 2)
44                 {
45                     //Print the unscrambled word and quit
46                 }
47             }
48             else
49             {
50                 if (option == 3)
51                 {
52                     //Just quit the program
53                 }
54             }
55         }
56     }
57 }  

Basically, I think I have the structure set up....but I don't know how to scramble the actual words...I know I should use the random generator to switch the characters but I don't really have any clues as to what else to do. I included the comments to enhance readability. If anyone could offer some suggestions that would be appreciated.Thanks, everyone!

Edited by hoshanaeckhart
spell missing

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  


Important Information

By using this site, you agree to our Guidelines and Privacy Policy.