import java.util.*
import java.io.*
public class Unscrambler
{
//-----------------------------------------------------------------------------------------
// This program reads a random word from a file created separately called words.txt that
// has been provided. The program then scrambles the word by swapping random letters a
// random number of times. The scrambled word is displayed with character indexes on top.
// The user selects 1 to swap a pair of letters, 2 to print the word unscrambled and quit,
// and 3 to simply quit. When the word is scrambled correctly, the computer congratulates
// the user, repeats the unscrambled word, and the number of steps it took to solve. An
// error message appears if invalid indexes are input by the user.
//-----------------------------------------------------------------------------------------
public static void main (String[] args) throws IOException
{
//Setting Up Variables and Scanners to read from User and words.txt
String words;
Scanner fileScan, wordsScan, optionScan;
int option;
boolean done = false;
Random generator = new Random();
fileScan = new Scanner (new File("words.txt"));
words = filescan.nextLine(generator.nextInt(22);
optionScan = new Scanner (System.in);
while (!done)
{
//Menu
System.out.prinln ("Welcome Computational Unscrambling!");
//read from User
option = optionScan.nextInt(3) + 1;
if (option == 1)
{
//Allow user to switch letters between index;
//If User unscrambles word, done == true;
}
else
{
if (option == 2)
{
//Print the unscrambled word and quit
}
}
else
{
if (option == 3)
{
//Just quit the program
}
}
}
}
}
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 dont really have any clues as what else to do. I included the comments to enhance readability. If anyone could offer some suggestions that would be appreciated.Thanks everyone!
This post has been edited by baavgai: 10 March 2013 - 03:08 PM
Reason for edit:: tagged

New Topic/Question
Reply



MultiQuote







|