Microsoft Word - Assign1 Cosc 1p03 Assignment 1 (Due date Jan 28th 16:00 est, Late date Jan 31st 16:00 est) Object To become familiar with Ragged Array Structures (array of arrays) and using 2-D array...

1 answer below »
i got zero one time when its done from here so please have a look carefully


Microsoft Word - Assign1 Cosc 1p03 Assignment 1 (Due date Jan 28th 16:00 est, Late date Jan 31st 16:00 est) Object To become familiar with Ragged Array Structures (array of arrays) and using 2-D array random indexing. Back Ground A word search puzzle consists of a board and a set of words. The board is usually laid out as a square of characters. In the assignment this square will be 25x25. The word set which is given requires the player to find the word within the board. Words may be represented forward, backward, up, down and on any of the 4 diagonals. The Assignment You are given a word puzzle which you must solve. The data file wordSearch.dat consists of 21 words followed by a 25x25 word board. You are to read the words into a ragged array. This array will consist of 21 rows, where each row represents 1 word. The board should be read into a second 25x25 char matrix. For each word in the word list, identify it's location in the board. For output, print the board with just the found words. The solution to the puzzle is given below. This also represents the desired output from your program. Found 21 I N PECNEREFER T R C O E E S I RL T O N FI UC T T C L AN PE C O I CKRM E L S EE OJ L T DBC ENTER S D O CP R T A A KI C S O Y OS KS B R N I AA Y O ED L G E M VDC E K Y E EEIR H A M CPTA E R N NYAH A R I ETM P A A IBI S M CUR SSP PROTOTYPE How you should proceed with the solution and things to think about. 1. Create the data structures for the ragged array to hold the word list. Each word in the list will represent a right sized char array. The board is simply a 25x25 char matrix. 2. Read the data file loading both the word list and the board. When reading the word list consider reading a word as a String, and then using the toCharArray method to convert the string to a right sized character array. 3. Write a small test routine which prints both of these data structures to a displayer or system output. It is nice to know that your program works correctly up to this point. The output should match the input. 4. Write a search routine which, for each char in the matrix, will search all 8 directions for each word in the list. 5. Consider using a 2nd 25x25 matrix only for output. Once a word is found, write it into this output matrix. Printing the output matrix will give the above output. The output matrix should be initialized to blank characters. Keep the problem manageable by implementing each search direction one at a time. E.g. get it working for finding words spelled forward first, then implement each additional direction 1 at a time. This allows for easy debugging. You will also notice, that once you get forward working, the rest are largely straight forward. Dealing with a matrix such as this will require keeping a close tab on upper and lower bounds (Exceptions such as ArrayOutOfBounds). A filter method private char getChar(int i, int j) can be used to index the puzzle matrix, implementing bounds checking. If a valid character can be returned then that character is returned, otherwise some non-alpha character can be returned which will result in a failed match. This simplifies the comparison algorithm. Submission Include in your submission, the IntelliJ project directory, zipped. Be sure your name and student number are included in your source file. Also, provide good commenting as per javaDoc standards (see class example code). Assignment submission is via Sakai.
Answered 4 days AfterJan 20, 2022

Answer To: Microsoft Word - Assign1 Cosc 1p03 Assignment 1 (Due date Jan 28th 16:00 est, Late date Jan 31st...

Sunitha answered on Jan 24 2022
120 Votes
WORD PUZZLE USING RAGGED ARRAY STRUCTURES (ARRAY OF ARRAYS) AND USING 2-D ARRAY RANDOM INDEXING
Objective
Understand the use of Ragged Array and Two-Dimensional array with random indexing.
Introduction to Assignment
Need to implement a word search puzzle. The input to the program is a .dat file which consists of 21 words and a 25x25 word board.
The program has to separate these two. The words have to be stored in the ragged array. And the word board has to be stored in the
25x25 two-dimensional array. The words given have to be searched in the word board. The words can appear in forward direction, backward direction, upward direction, downward direction and in other four diagonal directions (up-left, up-right, down-left, down-right).
For each word in the word list, identify it's location in the board. For output, print the board with just the found words.
Requirement Specification of Assignment
1. The given words have to be stored in the ragged array. The word board has to be stored in 25x25 two-dimensional array.
2. The words can be read as a string from the file and convert it to char array using the method toCharArray() .
3. Write methods to print the word list and word board to test the proper working of our algorithm.
4. Write the methods to search for the character in the matrix in all eight directions.
5. Save the found words into another two-dimesional matrix, preserving the position in input matrix. The output matrix should be initialized to blank characters.
6. Write separate methods for search words in each direction. It will be useful to debug the program.
7. Check the array index whenever you access the elements to avoid the array-out-of-bound exceptions. A filter method private char getChar(int i, int j) can be used to index the puzzle matrix, implementing bounds checking.
8. Submit the zipped IntelliJ project directory. Also, provide good commenting as per javaDoc standards (see class example code). Robert Lafore (2018), Cormen (2017), Corment et.al (2009), Brass (2008) and Karumanchi (2016)
Program WordPuzzle.java
package com.company;
import java.io.File;
import java.util.Scanner;
/*class that represents the Puzzle*/
class WordPuzzle {
int numWords=21; //number of words
int boardSize=25; //size of the puzzle board=25
char wordList[][] = new char[numWords][]; //list of words
char wordBoard[][]=new char[boardSize][boardSize]; // Word board
char solutionBoard[][]=new char[boardSize][boardSize]; //Solution board
WordPuzzle(String file) {
readFile(file); // read the input file
}
/*display the list of words (wordList)*/
void displayWordList()
{
System.out.println("\n\nThe List of Words (21)");
System.out.println("**********************\n");
for (int i = 0; i < wordList.length;i++) {
for (int j = 0;j < wordList[i].length; j++) {
System.out.print(wordList[i][j]);
}
System.out.println("");
}
}
/*Solve the puzzle by finding the existence of each word*/
void solvePuzzle()
{
System.out.println("Solving Puzzle.....");
int row=0;
/*set solution board to blank*/
for(int i=0;i for(int j=0;j solutionBoard[i][j]=' ';
/*Read each word from the word list*/
while(row searchWord(row);
row++;
}
displaySolutionBoard();
}
/*search for a word in the Word Board*/
int searchWord(int row)
{
// System.out.println("Searching word......");
int flag=1;
searchForward(row);
searchBackward(row);
searchUpward(row);
searchDownward(row);
searchUpright(row);
searchUpleft(row);
searchDownright(row);
searchDownleft(row);
return flag;
}
/*Search Forward*/
boolean searchForward(int row)
{
int k=0;
for (int i = 0; i < boardSize; i++) {
k=0;
for (int j = 0; j < boardSize; j++) {
char test=getChar(i,j);
if(Character.isAlphabetic(test)) {
if ((wordList[row][k] == wordBoard[i][j])||(Character.toUpperCase(wordList[row][k]) == wordBoard[i][j])) {
k++;
if(k==wordList[row].length){
copyX(row,i,j,'f');
//System.out.print("The word ");
// printWord(row);
// System.out.print(" Found at row :...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here