Question
Java Word Game Java Word Ladder Game Java Word-Ladder Game Doublets Can anyone help me write the methods for this assignment per instructions given? import
Java Word Game Java Word Ladder Game Java Word-Ladder Game Doublets
Can anyone help me write the methods for this assignment per instructions given?
import java.util.List; /** * WordLadderGame.java Defines an interface for games that construct word * ladders. See https://en.wikipedia.org/wiki/Word_ladder for a definition and * history. * * Word ladders are constructed in the context of some predefined list of valid * words. We will refer to this word list as the lexicon. An implementing class * of this interface must provide a way to explicitly set the lexicon. This will * typically be done in the constructor. * * For the purposes of this interface and all implementing classes, a string is * a word if and only if it appears in the current lexicon. In the documentation * of each interface method, the use of 'string' means that the referenced * string does not have to be a word, while the use of 'word' implies that the * referenced string must be a word. * */ public interface WordLadderGame { /** * Returns the Hamming distance between two strings, str1 and str2. The * Hamming distance between two strings of equal length is defined as the * number of positions at which the corresponding symbols are different. The * Hamming distance is undefined if the strings have different length, and * this method returns -1 in that case. See the following link for * reference: https://en.wikipedia.org/wiki/Hamming_distance * * @param str1 the first string * @param str2 the second string * @return the Hamming distance between str1 and str2 if they are the * same length, -1 otherwise */ int getHammingDistance(String str1, String str2); /** * Returns a word ladder from start to end. If multiple word ladders exist, * no guarantee is made regarding which one is returned. If no word ladder exists, * this method returns an empty list. * * Depth-first search with backtracking must be used in all implementing classes. * * @param start the starting word * @param end the ending word * @return a word ladder from start to end */ List
---------------------------------------------------------------------------------------------
import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.util.Arrays; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.LinkedList; import java.util.List; import java.util.Scanner; import java.util.TreeSet; /** * Doublets.java * Provides an implementation of the WordLadderGame interface. The lexicon * is stored as a TreeSet of Strings. * */ public class Doublets implements WordLadderGame { //////////////////////////////////////////// // DON'T CHANGE THE FOLLOWING TWO FIELDS. // //////////////////////////////////////////// // A word ladder with no words. Used as the return value for the ladder methods // below when no ladder exists. List
----------------------------------------------------------------------------------------
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.List; /** * ExampleClient.java * Provides example calls to WordLadderGame methods in an instance of * the Doublets class. * * The word list files must be extracted into the current directory * before running this class. * * jar xf WordLists.jar * */ public class ExampleClient { /** Drives execution. */ public static void main(String[] args) throws FileNotFoundException { WordLadderGame doublets = new Doublets(new FileInputStream(new File("sowpods.txt"))); System.out.println(doublets.getHammingDistance("tiger", "tiger")); System.out.println(doublets.getHammingDistance("tiger", "eagle")); System.out.println(doublets.getHammingDistance("war", "eagle")); System.out.println(doublets.getHammingDistance("barner", "bammer")); System.out.println(doublets.isWord("tiger")); System.out.println(doublets.isWord("eagle")); System.out.println(doublets.isWord("aubie")); System.out.println(doublets.getWordCount()); System.out.println(doublets.isWordLadder(Arrays.asList("cat", "cot", "zot", "dot"))); System.out.println(doublets.isWordLadder(Arrays.asList("cat", "cot", "pot", "dot"))); System.out.println(doublets.getNeighbors("tiger")); System.out.println(doublets.getLadder("cat", "hat")); System.out.println(doublets.getMinLadder("cat", "hat")); } } /* RUNTIME OUTPUT 0 4 -1 2 true true false 267751 true [liger, niger, tiler, timer, titer, tiges] [cat, bat, eat, fat, gat, hat] [cat, hat] */
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started