Implement the following pseudocode

Assignment Help Data Structure & Algorithms
Reference no: EM13945515

public class WordSearch {

private static ArrayList<String> board = new ArrayList<String>();
private static Scanner scanner;

public static void readBoard() {
String line;
while (true) {
line = scanner.nextLine();
if (line.equals(""))

break;
board.add(line.replaceAll(" ","").toUpperCase());
}
}

public static void printBoard() {
int rows = getRows();
for (int row=0; row<rows; row++)
System.out.println(board.get(row));
}

public static int getRows() {
return board.size();
}

public static int getCols() {
return board.get(0).length();
}

public static void createScanner() {
try {
scanner = new Scanner(new java.io.File("WordSearchInput.txt"));
} catch (Exception e) {
System.out.println();
System.exit(1);
}
}

public static void processWords() {
while (scanner.hasNext()) {
String word = scanner.next();
findWord(word);
}
}

public static void findWord(String word) {
int rows = getRows();
int cols = getCols();
for (int row=0; row<rows; row++)
for (int col=0; col<cols; col++)
findWord(word,row,col);
}

public static void findWord(String word, int row, int col) {
for (int drow=-1; drow<=1; drow++)
for (int dcol=-1; dcol<=1; dcol++)
findWord(word,row,col,drow,dcol);
}

public static void findWord(String word, int row, int col, int drow, int dcol) {
int rows = getRows();
int cols = getCols();
for (int offset=0; offset<word.length(); offset++) {
int targetRow = row + offset*drow;
int targetCol = col + offset*dcol;
if ((targetRow < 0) ||
(targetRow >= rows) ||
(targetCol < 0) ||
(targetCol >= cols))

return;
char boardChar = board.get(targetRow).charAt(targetCol);
char wordChar = word.charAt(offset);
if (boardChar != wordChar)
// mismatch, so we're done
return;
}
System.out.printf("%s at %d,%d direction %d,%dn",
word, row, col, drow, dcol);
}

public static void main(String[] args) {
createScanner();
readBoard();

Reference no: EM13945515

Questions Cloud

How would that ratio change if the firm : How would that ratio change if the firm can earn only a 10% rate of return on its investments?
Error code in unning this program in raptor : I need an input statement that would allow the user to input any day of the week for steps walked and be able to input any number for step walked on any day of the week.
Write a short note on probability sampling methods : What techniques would you suggest in an effort to minimize and detect subject dishonesty in a Social Science research? Write a short note on probability and non-probability sampling methods
How should the interests of competing groups be balanced : Should environmental groups play a role in preserving those regions threatened by human encroachment, even if it is jeopardizing interests of the economic growth? How should the interests of competing groups be balanced?
Implement the following pseudocode : private static ArrayList board = new ArrayList ();
What should the stock price be today : If the discount rate is 15% and the steady growth rate after 3 years is 4%, what should the stock price be today?
A two digit number is such that the product of its digits is : A two digit number is such that the product of its digits is 35. When 18 is added to the number, the digits interchange their places. Find the number. A motor boat whose speed is 18 km/hr in still water takes 1 hour more to go 24 km upstream than to ..
What human impacts on natural cycling process of ecosystems : Identify a natural ecosystem in Arizona which you live or one near to where you live? How does this ecosystem support you? What are some human impacts on the natural cycling process of ecosystems in your community?
Write assembly language program for the marie processor : Please refer to the attachment for the general structure of the assembly language source code and more specifications regarding the assembly program

Reviews

Write a Review

Data Structure & Algorithms Questions & Answers

  Research on algorithms flowcharts and pseudocodes

Using the Internet, further research on the following: Algorithms, Flowcharts, Pseudocodes

  Calculating an arithmetic mean, median and mode

Calculate an arithmetic mean, median, and mode for up to fifty test scores. The information are contained in a text file. To determine the median, first sort the array.

  Algorithm for finding smallest element in unsorted array

Consider the following algorithm for finding the smallest element in an unsorted array: RANDOMMIN(A[1 .. n]). What is the exact expected number of executions of line ( )?

  Implementing ajax programming

In the AJAX scripts construct, refer to the DSN datasource as flamingo. Even though its not in your own folder or directory, it has been set up as SYSTEM DSN, so your AJAX script will have access to it.

  Write a pseudocode for divide-and-conquer algorithm

Write a pseudocode for divide-and-conquer algorithm for the exponentiation problem of computing where a>0 n is a positive integer

  Derive a set of relational tables from the er diagram

Outline the kinds of anomalies that can arise in the scenario given above by using un-normalized tables. Show how the table created in task 2 could be re-organised into separate tables to avoid anomalies

  Search a sorted array of floating point numbers

You need to write a program which uses binary search to search a sorted array of floating point numbers - Create an array of doubles, using the following statement. Notice that the array is sorted.

  Find an optimal hamilton circuit stating at vertex c

find an optimal Hamilton Circuit stating at Vertex C

  Question about unix commands

Assume you have a document called records.txt having the list of employee id and workers names. Every line contains a single employee id immediately followed by the employee name in the format Last name, First name.

  Online vs. face-to-face classes

Communication A significant distinction between online and face-to-face classes lies in the area of communication.

  Karatsuba''s divide-and-conquer algorithm

In class we discussed Karatsuba's divide-and-conquer algorithm for integer multiplication, which multiplies n-bit numbers by recursively multiplying n bit numbers. We take two numbers X and Y and split them each into their most significant half a..

  Develop the flow diagram of the information

Develop the flow diagram of the information and any control elements needed to ensure proper access for the information. A diagram of the information flow and any elements controlling proper access to the information it uses

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd