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

  Implement an open hash table

In this programming assignment you will implement an open hash table and compare the performance of four hash functions using various prime table sizes.

  Use a search tree to find the solution

Explain how will use a search tree to find the solution.

  How to access virtualised applications through unicore

How to access virtualised applications through UNICORE

  Recursive tree algorithms

Write a recursive function to determine if a binary tree is a binary search tree.

  Determine the mean salary as well as the number of salaries

Determine the mean salary as well as the number of salaries.

  Currency conversion development

Currency Conversion Development

  Cloud computing assignment

WSDL service that receives a request for a stock market quote and returns the quote

  Design a gui and implement tic tac toe game in java

Design a GUI and implement Tic Tac Toe game in java

  Recursive implementation of euclids algorithm

Write a recursive implementation of Euclid's algorithm for finding the greatest common divisor (GCD) of two integers

  Data structures for a single algorithm

Data structures for a single algorithm

  Write the selection sort algorithm

Write the selection sort algorithm

  Design of sample and hold amplifiers for 100 msps by using n

The report is divided into four main parts. The introduction about sample, hold amplifier and design, bootstrap switch design followed by simulation results.

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