package cse1030; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * A word puzzle where the puzzle word is formed by randomly * shuffling the letters of the solution word. * *

* Many scrambled word puzzles have multiple solutions but * this class assumes that there is only one solution for * the puzzle. * * @author EECS1030_2014_15W * */ public class ScrambledWordPuzzle extends AbstractWordPuzzle { private String solution; /** * Creates a scrambled word puzzle given the solution word. * * @param solutionWord the puzzle word */ public ScrambledWordPuzzle(String solutionWord) { super(); this.solution = solutionWord; List t = new ArrayList(); for (char c : solutionWord.toCharArray()) { t.add(c); } Collections.shuffle(t); StringBuilder b = new StringBuilder(); for (Character c : t) { b.append(c); } this.setPuzzleWord(b.toString()); } /** * Get the solution for this reverse word puzzle. * * @return the solution for this reverse word puzzle * @see cse1030.AbstractWordPuzzle#getSolution() */ @Override public String getSolution() { return this.solution; } }