Question

Complete code and answer question in comments: Package hw4; import java.util.ArrayList; public c...

Complete code and answer question in comments:
Package hw4;
import java.util.ArrayList;

public class WordGame {
        /*
         * Returns all strings that appear
         * as a consecutive horizontal or vertical sequence of letters
         * (left-right, right-left, up-down, or down-up)
         * in the array board and also appear in dict.
         * Note that the same word may appear multiple times
         * on the board, and will then be multiple times in 
         * the returned array.
         * 
         * dict is assumed to be in alphabetical order
         * board is assumed to be rectangular
         */
        public static String[] search(String[] dict, char[][] board) {
                /*The following line contains <String>, this means
                 * that the ret is an ArrayList that contains String. It is an 
                 * ArrayList of only Strings. 
                 */
                ArrayList<String> ret = new ArrayList<String>();
                int height = board.length;
                
                // Set width to 0 for an empty board,
                // and to the width for first line otherwise,
                // because we assume the board is a rectangle
                int width = board.length==0 ? 0 : board[0].length;
                
                // TODO Generate substrings of the board
                // and check if they are in the dictionary
                // by calling inDictionary (which you implement).
                // If they are, use ret.add to add them
                // to the array that gets returned.
                // Character.toString, String+char, and String+=char
                // can all be useful here.
                // You may want to see https://docs.oracle.com/javase/8/docs/api/java/lang/String.html
        // and https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html
                //
                // TODO (10% of your grade): if your board
                // has height h and width w, how many strings
                // do you need to check using inDictionary
                // (assume that you do nothing to filter out
                // duplicates or, equivalently, that the board
                // is such that there are no duplicates)
                // ANSWER: 
                // EXPLANATION OF THE ANSWER:

                // This line converts ArrayList<String> to String []
                return ret.toArray(new String[0]);
        }
}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Salution impert dava uiArray List Public class woxdthame mt hight bend Length Saing sa Chasactes . to Sting (bod ) or one -leet adol s) γ do es change cohen gou check cipandda / cheekincup HM34 o.in Dictionary (eict, s)) HLO e add US) ( his dine Con

Add a comment
Know the answer?
Add Answer to:
Complete code and answer question in comments: Package hw4; import java.util.ArrayList; public c...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Complete the code: package hw4; import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.Scanner; /* * This...

    Complete the code: package hw4; import java.io.File; import java.io.IOException; import java.util.LinkedList; import java.util.Scanner; /* * This class is used by: * 1. FindSpacing.java * 2. FindSpacingDriver.java * 3. WordGame.java * 4. WordGameDriver.java */ public class WordGameHelperClass { /* * Returns true if an only the string s * is equal to one of the strings in dict. * Assumes dict is in alphabetical order. */ public static boolean inDictionary(String [] dict, String s) { // TODO Implement using binary search...

  • Java code about writing two methods: public static String randomStringone(int length) public static String randomStringtwo(int length)...

    Java code about writing two methods: public static String randomStringone(int length) public static String randomStringtwo(int length) This method should return a String of random lowercase letters with the given length by using for loops. To generate a random lowercase letter, use a local Random variable and the method nextInt() to generate a number between 97 and 122, then cast the result to a char. The method nextInt() can be found here: https://www.geeksforgeeks.org/java-util-random-nextint-java/    In randomStringone(), you should use String concatenation...

  • Please help me with this Java problem. Would greatly appreciate comments in the code as well:...

    Please help me with this Java problem. Would greatly appreciate comments in the code as well: Define a class called Counter whose internal "count" variable is a basic integer counter. This class track that count from its instantiation in the constructor (can be set to any positive integer, or 0). The count should never be allowed to be negative. Include methods that will set the counter to 0, increase the count by 1, and decrease the count by 1. Include...

  • complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class...

    complete this in java import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Random; import java.util.Scanner; public class WordDetective { /** * Finds the specified set of words in the specified file and returns them * as an ArrayList. This finds the specified set in the file which is on the * line number of the set. The first line and set in the file is 1. * * This returns an ArrayList with the keyword first, then : and then followed...

  • JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {    ...

    JAVA programming 9.9 Ch 9, Part 2: ArrayList Searching import java.util.ArrayList; public class ArrayListSet {     /**      * Searches through the ArrayList arr, from the first index to the last, returning an ArrayList      * containing all the indexes of Strings in arr that match String s. For this method, two Strings,      * p and q, match when p.equals(q) returns true or if both of the compared references are null.      *      * @param s The string...

  • Complete the Java command line application. The application accepts a URL from the command line. This...

    Complete the Java command line application. The application accepts a URL from the command line. This application should then make a HTTP request to “GET” the HTML page for that URL, then print the HTTP header as well as the HTML for the page to the console. You must use the Java “socket” class to do all network I/O with the webserver. Yes, I’m aware this is on Stack Overflow, but you must understand how this works, as you will...

  • QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes...

    QUESTION The ReadFile class opens and reads a text file. The WriteFile class opens and writes to a file. Compile and run these programs. There are several ways to read/write text files. The examples shown here are just one way of achieving this. Look at the API for the BufferedReader class. The readline() method is a simple way to read the text file line by line. It returns null when the end of the file has been reached. https://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html Look...

  • import java.util.List; import java.util.ArrayList; import java.util.LinkedList; public class ListPractice {       private static final int[]...

    import java.util.List; import java.util.ArrayList; import java.util.LinkedList; public class ListPractice {       private static final int[] arr = new int[100000];    public static void main(String[] args) {        for(int i=0; i<100000; i++)            arr[i] = i;               //TODO comment out this line        LinkedList<Integer> list = new LinkedList<Integer>();               //TODO uncomment this line        //List<Integer> list = new ArrayList<Integer>();               //TODO change the rest of the...

  • package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public...

    package Lab11; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class Lab10 {    public static void main (String [] args)    {    // ============================================================    // Step 2. Declaring Variables You Need    // These constants are used to define 2D array and loop conditions    final int NUM_ROWS = 4;    final int NUM_COLS = 3;            String filename = "Input.txt";    // A String variable used to save the lines read from input...

  • What if you had to write a program that would keep track of a list of...

    What if you had to write a program that would keep track of a list of rectangles? This might be for a house painter to use in calculating square footage of walls that need paint, or for an advertising agency to keep track of the space available on billboards. The first step would be to define a class where one object represents one rectangle's length and width. Once we have class Rectangle, then we can make as many objects of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT