CPTR 124 Fundamentals of Programming
In this lab you will use a two-dimensional array to implement a word search puzzle.
- As usual, you are invited to work with a partner.
Please submit one lab write up per team.
- Create a project named Lab10b.
- Background. A word search puzzle consists of words hidden in a rectangular block of random
characters. Write a Java program to produce such a puzzle.
- Implementation details.
Your program should read the list of words from a textfile. The name of the file is specified on the command line as
the programs we wrote in class. The file should contain ten words, each on its own line.
Place the words in a 20 x 20 block filled with random letters. Provide the puzzle, the list of words to find, and an answer key.
The words should be placed randomly in several ways:
- The position of a word should be determined randomly.
- Whether a word is printed horizontally, vertically, or diagonally should be determined randomly.
- Whether a word is printed forwards (left-to-right or top-to-bottom) or backwards (right-to-left or bottom-to-top) should be determined randomly.
This means you should not determine ahead of time how many words are printed backwards or diagonally, etc. Since the placement is done entirely at random, some puzzles, although rare, may contain no diagonally-placed words, or no backwards words; however, multiple runs of your program over the same list of words must clearly demonstrate that your program satisfies all the requirements listed in this specification.
Another use of randomness is in the selection of letters to fill in around the words to hide. They should be chosen at random, not predetermined.
Your program should be able to handle correctly words that overlap, such as:
R O S T A T I C J C A E V A
Notice how JAVA and VECTOR overlap at V, and STATIC and VECTOR overlap at T.
The words in the file may may consist of both upper- and lowercase letters, but your program should capitalize all their letters before using them in the puzzle.
- Output.
The program should produce the following output, in the following order:
- the puzzle
- the list of words to find
- The answer key
Here is the output of a sample run.
P M N R B L H R K X R J F T K B P F W C I E X L B U M W E P U V M U Q R N L T B B P M R K L P E C C N T M D O D F Q W G X K T H A F X B O X U T M G H K S E B E C E Z X Y M B R M M G R R L L K M K Y T O R Z Z Q D L U P G H A S R F W R P K E Z D X R T F Y A U V M I G I P E T O W Z O O W E D O B V T J X M N A V J S D W C X U R R Y X T A E L E P H M Z E W B S N A N G R U P C J R R X P L T E V R Y I E Z W L U Y I M P E E R M B E I U A H P X I I M E M O R Y B L L Y T X J R T R T U U E G L D O O E Y I D G C J H G O D J X G C D B U R K J Q P A E Y C P C V G R F Q B X H X E V H U M J G V W E R M R L T Q S R P L X Z L H O L K Y S M D P S Y A E V C O Y B O J M C H K S F E X A S L E Z N E M J O G W F Q N O V U X I L Z D M E V I T A R E T I W R K N H D V X X A I Z G S L S M L A N O I T I D N O C T Z F COMPUTER ALGORITHM JAVA PROGRAM COMPILER PROCESSOR MEMORY ITERATIVE RECURSIVE CONDITIONAL R P E R C C O O U G M R R P A S A U M I V T M V A E H E J R R T E I P M E M O R Y L R R I O P C G M E L O S A C S O E V I T A R E T I R L A N O I T I D N O C
- As always, use the standard Java coding style conventions.
- When you believe the program works correctly:
- recheck your style to make sure it is similar to the Sun guidelines,
- let me check and review your lab with you,
- get a Lab Report (one per team),
- close your project, exit Eclipse, and log out from your workstation.