Java RandomString Class
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13818297/hangman-randomstring-class">HangMan RandomString Class</a>  </p>
</blockquote>



<p>Here are the directions:</p>

<p>Create a <code>RandomString</code> class and implement the following:</p>

<ol>
<li><p>Create a file named guess_phrases.txt that contains phrases to be guessed in your Hangman game. This file will have one guess phrase per line. </p></li>
<li><p>A constructor that receives the name of a file to get string values from. The constructor should read in the phrases from the file and store them for later use. </p></li>
<li><p>A method that returns a random string value from the file; this value shouldn't be repeated until all guess phrases in the file have been used.</p></li>
</ol>

<p>Create a main method to test that next is working correctly by repeatedly calling next &amp; printing the result – you should not have any repeats, and the phrases should not be in the same order as in the file.</p>

<p>I created a file called *guess_phrases.txt* with random phrases. When I run this I get an error, also it is not printed randomly, why is this? How can I fix this ?</p>

<p>This is what I have in the RandomString Class</p>

<pre><code>public class RandomString {

    Random random = new Random();
    ArrayList&lt;String&gt; guessPhrases = new ArrayList&lt;String&gt;();
    Scanner fileScan;

    public RandomString(String guessPhrases) throws FileNotFoundException {

        // create a Scanner object to read from the file
        fileScan = new Scanner(new File("guess_phrases.txt"));

        // add all of the phrases from the file into the ArrayList
        while (fileScan.hasNext()) {

            String line = guessPhrases.nextLine(); // get input
            System.out.println(line); // print line
            guessPhrases.add(line); // add line to array list
        }
    }

    public String next() {
        int i = random.nextInt(guessPhrases.size());
        return guessPhrases.get(i);
    }

    public static void main(String[] args) {

    }
}
</code></pre>
