Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MUST BE ABLE TO BE PUT DIRECTLY INTO NOTEPAD TO BE USED FOR WEB PROGRAMMING. PLE

ID: 3666285 • Letter: M

Question

MUST BE ABLE TO BE PUT DIRECTLY INTO NOTEPAD TO BE USED FOR WEB PROGRAMMING. PLEASE DO NOT JUST COPY AND PASTE AVAILABLE CODE ALREADY ON THE INTERNET.

(Project: Crossword Puzzle Generator) Most people have worked a crossword puzzle, but few have ever attempted to generate one. Generating a crossword puzzle is suggested here as a string-manipulation project requiring substantial sophistication and effort.

There are many issues you must resolve to get even the simplest crossword puzzle generator program working. For example, how does one represent the grid of a crossword puzzle in the computer? Should one use a series of strings, or use double-subscripted arrays?

You need a source of words (i.e. a computerized dictionary) that can be directly referenced by the program. In what form should these words be stored to facilitate the complex manipulations required by the program?

The really ambitious reader will want to generate the clues portion of the puzzle, in which the brief hints for each across word and each down word are printed for the puzzle worker. Merely printing a version of the blank puzzle itself is not a simple problem.

1. Do not use Alerts/Popups.

2. You must use an Array.

3. You must write and call your own function(s); at least one function is required.

4. You do not need to persist the array outside of the current session. For example, you do not need to save the array to a text file, cookie, or database.

5. You must use at least 1 loop, 1 if statement, and built-in String methods.

Explanation / Answer

package Model.Puzzles; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; import java.util.Vector; import Model.WordList; import Model.Puzzles.Parts.*; import Utility.RandomHelper; import Utility.Vector2; public class PuzzleGenerator { /** * Main method for creating puzzles. Passes the data off to the respective * method based on the puzzle type. * @param type * The type of puzzle to be created. * @param size * The size of the puzzle (size X size) * @param wordList * The list of words used to create the puzzle * @return */ public static Puzzle generatePuzzle(PuzzleType type, int size, WordList wordList) { switch (type) { case CrossWord: return generateCrossWord(size, wordList); case WordSearch: return generateWordSearch(size, wordList); } return null; } /** * Generates a word search puzzle. * * @param size * The square size of the puzzle * @return */ private static WordSearch generateWordSearch(int size, WordList words) { WordSearchCell[][] wordSearchArray = new WordSearchCell[size][size]; // initialize array to #s for (int i = 0; i diagonal up // direction 3 -> diagonal down int direction = rand.nextInt(100)%3; // word is backwards, so flip if (orientation == 1) { word = flipString (word); } // for loop to try first locations for (int attempt = 0; attempt = size)) { validLocation = true; } break; } case 1: { if (!(y + word.length() >= size)) { validLocation = true; } break; } case 2: if (!(x + word.length() >= size) && !(y - word.length() < 0)) { validLocation = true; } break; case 3: { if (!(x + word.length() >= size) && !(y + word.length() >= size)) { validLocation = true; } break; } } } while (!validLocation); // try to fill word. if bad intersection, get out and try a new spot int index; for (index = 0; index 0; j--) { //System.out.println("j = " + j + " i = " + index + " x = " + x + " y = " + y); // walk back through the word, depending on direction switch (direction) { case 0: x--; break; case 1: y--; break; case 2: x--; y++; break; case 3: x--; y--; break; } newPuzzle[x][y].setChar(originalPuzzle[x][y].getChar ()); newPuzzle[x][y].setPartOfWord(false); } // get out and try a new spot break; } // end else } // end for // word successfully placed, return newPuzzle if (index >= word.length ()) { return newPuzzle; } } // end for return originalPuzzle; } public static WordSearchCell[][] addRandomChars (WordSearchCell[][] puzzle) { int size = puzzle.length; // fill with random chars for (int i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote