ArrayList

I have an error of incompatiable types in the following code and just can't seem to figure it out.  Can anyone lend me a hand?

Here is the code:

/*
 * readDictionaryFile.java
 *
 * Created on November 3, 2004, 12:46 AM
 */

/**
 *
 * @author  Shannon DM  Rice
 */

import java.io.*;
import java.util.*;
import java.lang.*;

public class readDictionaryFile {

String readList;
String dictionaryWord;
String scrambledDictWord;
 
    /** Creates a new instance of readDictionaryFile */
    public readDictionaryFile() {
       
        readFile();
     
    }
   
    public void readFile() throws IOException {
                 
        File dictionaryFile = new File("dictionayWords.txt");//declare file      
        FileReader fReader = new FileReader(dictionaryFile);//dictionaryFile object
       
        if (dictionaryFile != null) {
           
            BufferedReader buffReader = new BufferedReader(fReader);//input from dictionaryFile
            String line;//word
       
            ArrayList word = new ArrayList();//create default word array
            ArrayList scrambled = new ArrayList();//create default scrambled array
           
        while (null != (line = buffReader.readLine())) {
            word.add(line);//add word to end of array list
            scrambled.add(scramble(line));//add scsrambled word to end of array list
            }
           
         
            String dictionaryWord[] = new String[word.size()];
            dictionaryWord = (String[])word.toArray(dictionaryWord);
           
            String scrambledDictWord[] = new String[scrambled.size()];
            scrambledDictWord = (String[])scrambled.toArray(scrambledDictWord);
     
        double randomNumber = (Math.random() * scrambledDictWord.length);//select random scrambed word

--------------------error is here------------------
--------------------Found:  java.lang.String  Required:  java.util.ArrayList---

           scrambled = scrambledDictWord[(int)randomNumber];//sets the scrambedWord field
           word = dictionaryWord[(int)randomNumber];//sets the unscrambledWorld field

----------------------------------------------------------------------------------------------------------------------            
           buffReader.close();
       }
       
        else {
            throw new IOException("File not found");
        }
    }      

    public String getunscrambledWord(){
        return dictionaryWord;
    }
   
    public String getscrambledWord(){
        return scrambledDictWord;
    }
   

    public String scramble(String word) {
        int size = word.length();//word length
        StringBuffer buffer = new StringBuffer();//creates empty buffer
       
        for (int i = 0; i + 1 < size; i += 2) {
            buffer.append(word.charAt(i + 1));
            buffer.append(word.charAt(i));
        }

        if (buffer.length() < word.length()) {
            buffer.append(word.charAt(word.length() - 1));
        }
   
    return buffer.toString();
    }
   
}
shannonriceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

objectsCommented:
>   scrambled = scrambledDictWord[(int)randomNumber];//sets the scrambedWord field

you cannot assign a String to an ArrayList
perhaps should be:

String word = scrambledDictWord[(int)randomNumber];

What is it you want to achieve?
0
petmagdyCommented:
the correction is:

import java.io.*;
import java.util.*;
import java.lang.*;

public class readDictionaryFile {

String readList;
String dictionaryWord;
String scrambledDictWord;
 
    /** Creates a new instance of readDictionaryFile */
    public readDictionaryFile() {
        try
        {
            readFile();
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }
   
    public void readFile() throws IOException {
                 
        File dictionaryFile = new File("dictionayWords.txt");//declare file      
        FileReader fReader = new FileReader(dictionaryFile);//dictionaryFile object
       
        if (dictionaryFile != null) {
           
            BufferedReader buffReader = new BufferedReader(fReader);//input from dictionaryFile
            String line;//word
       
            ArrayList word = new ArrayList();//create default word array
            ArrayList scrambled = new ArrayList();//create default scrambled array
           
        while (null != (line = buffReader.readLine())) {
            word.add(line);//add word to end of array list
            scrambled.add(scramble(line));//add scsrambled word to end of array list
            }
           
         
            String dictionaryWord[] = new String[word.size()];
            dictionaryWord = (String[])word.toArray(dictionaryWord);
           
            String scrambledDictWord[] = new String[scrambled.size()];
            scrambledDictWord = (String[])scrambled.toArray(scrambledDictWord);
     
        double randomNumber = (Math.random() * scrambledDictWord.length);//select random scrambed word


           scrambled.add(scrambledDictWord[(int)randomNumber]) ;//sets the scrambedWord field
           scrambled.add(dictionaryWord[(int)randomNumber]);//sets the unscrambledWorld field

           buffReader.close();
       }
       
        else {
            throw new IOException("File not found");
        }
    }    

    public String getunscrambledWord(){
        return dictionaryWord;
    }
   
    public String getscrambledWord(){
        return scrambledDictWord;
    }
   

    public String scramble(String word) {
        int size = word.length();//word length
        StringBuffer buffer = new StringBuffer();//creates empty buffer
       
        for (int i = 0; i + 1 < size; i += 2) {
            buffer.append(word.charAt(i + 1));
            buffer.append(word.charAt(i));
        }

        if (buffer.length() < word.length()) {
            buffer.append(word.charAt(word.length() - 1));
        }
   
    return buffer.toString();
    }
   
}
0
shannonriceAuthor Commented:
I am trying to create a scramble word game.  I want to select a random word from the dictionaryWord.txt (45,500 words) and scramble it then output it to a JPanel.  I am new to programming and could be going about this all wrong.
0
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

petmagdyCommented:
ahhhhh ok,
replace:

>>           scrambled = scrambledDictWord[(int)randomNumber];//sets the scrambedWord field
>>           word = dictionaryWord[(int)randomNumber];//sets the unscrambledWorld field

with:
       this.dictionaryWord = scrambledDictWord[(int)randomNumber];
        this.scrambledDictWord = dictionaryWord[(int)randomNumber];


0
petmagdyCommented:
also don't forget to change readDictionaryFile() constructor to:

    public readDictionaryFile() {
        try
        {
            readFile();
        }
        catch(Exception ex)
        {
            System.out.println(ex.getMessage());
        }
    }
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
shannonriceAuthor Commented:
Thank you petmagdy!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.