Purchase Solution

A Brief Explanation of Pseudo-Code

Not what you're looking for?

Ask Custom Question

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();

Purchase this Solution

Solution Summary

This brief answer will describe what pseudo-code is and convert Java code to it. 293 words.

Solution Preview

Hello,

My name is Jim. I hope I will answer any questions you have.

Pseudo-code is just an informal way of writing out the logic used to solve a problem, without getting involved in the details of any specific computer language.

Here's an example of pseudo-code for the readBoard function:

READ ALL LINES FROM THE FILE.
WHILE READING THEM, ELIMINATE ALL CARRAIGE RETURNS, MAP TO UPPERCASE, AND ADD EACH LINE TO THE ...

Purchase this Solution


Free BrainMass Quizzes
Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Javscript Basics

Quiz on basics of javascript programming language.

Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.