last updated: Mon Mar 18 15:38:50 EST 2002

CS1007
Spring 2002
Homework #4
due Thu Mar 28, by 6AM -- electronic submission

hardcopy due IN CLASS: 11.05AM cs1007-002; 2.45PM cs1007-001

goal.
The goals of this assignment are to:

  1. learn how to work with keyboard input
  2. learn how to use 2-dimensional arrays

wordfind.
You need to write a program that will let you play a nonsense word find game. Your program will generate a 2-dimensional array of characters, display the array to the user and ask the user to enter "words" to find in the array.
The reason that "words" is in quotes is because the words are really just sequences of letters and aren't necessarily words that belong to any natural (i.e., spoken) language. The 2-dimensional array that your program generates will be done randomly, so there is no guarantee that it will actually contain any real words from any language.

specifications.
Your program will do the following (the overall logic of your code -- i.e., following the steps outlined below -- is worth 0.6 points):

  1. prompt the user to enter the size of the 2-dimensional array (0.1 points)
  2. read the user's input as a String (using Keyboard class, as below; 0.5 points) and convert the input to an int (0.2 points)
  3. construct a square array according to the size the user enters and initialize the content of the array to randomly chosen lower case letters (0.2 points)
  4. display the array to the user, formatted sensibly (0.2 points)
  5. loop as follows:
    1. prompt the user for input: enter word to find (9 to quit): (0.1 points)
    2. read the user's input as a String (0.1 points) (Hint: use your Keyboard class, as below)
    3. if the user enters "9", then terminate the program (0.2 points)
    4. otherwise, search the square array for the word the user entered
    5. first search row-wise (i.e., horizontally) (using findInRow() method, as below; 0.8 points)
    6. then column-wise (i.e., vertically) (using findInColumn() method, as below; 0.8 points)
    7. if the word is found in the array, then replace it with '.' characters (using either method replaceInRow(), 0.8 points; or replaceInColumn(), 0.8 points; as below)
    8. if the word is not found in the array, then print a message to the user: word not found. (0.1 points)
    9. loop back to a.

notes.

program.
Your program will consist of 3 classes. You can click on the links below for skeletons of the first two classes. You must write the third from scratch.

  1. Complete the Keyboard class. As instructed by the comments in the code, write the following method:
  2. Complete the Square class. As instructed by the comments in the code, declare any necessary global constants and/or variables, write a constructor and the following methods:
  3. Write a main class, named hw4<yourCUNIXusername>.java containing a single main method that controls the program as it runs through the steps described in the specification section (above).

sample run.
Below is a sample run. The unix command line is highlighted in bold font.

unix$ java hw4eis2003
enter size for square: 10
clssqrdets
wizibsyphg
hrmagwpuge
evuqmiisah
iyvhvlfkkx
ipzwehgdpl
knjalmpjmc
jkyniyzste
ffkirnhfvg
fyrwecsrzg
enter word to find (9 to quit): lire  
clssqrdets
wizibsyphg
hrmagwpuge
evuqmiisah
iyvhvlfkkx
ipzwehgdpl
knja.mpjmc
jkyn.yzste
ffki.nhfvg
fyrw.csrzg
enter word to find (9 to quit): IS
clssqrdets
wizibsyphg
hrmagwpuge
evuqmi..ah
iyvhvlfkkx
ipzwehgdpl
knja.mpjmc
jkyn.yzste
ffki.nhfvg
fyrw.csrzg
enter word to find (9 to quit): sssss
word not found
enter word to find (9 to quit): 9

source code.
Your source code (i.e., your .java file) but be neat and clearly commented. You must have a header comment and you should comment the end of each block (i.e., each }). You need to comment each method that you write within in each class.

submission.
Follow the submission instructions carefully!!! If you don't, human intervention will be required to fix your mistakes, and you will lose 0.5 points.

  1. Name your homework files properly.
    You will submit 3 files:
    1. hw4<yourCUNIXusername>.java
      For example, mine is called hw4eis2003.java.
    2. Square.java
    3. Keyboard.java

  2. Submit your files electronically.
    You need to turn in ALL the Java source code, i.e., all three files listed above. Follow instructions on the assignments page.

  3. Turn in a harcopy of your program during THE FIRST 5 MINUTES OF class.
    Print out the homework template cover page (http://www.columbia.edu/~cs1007/hw-template.html) and fill it out.
    Staple the cover page to a hardcopy (print-out) of your program. You need to turn in ALL the Java source code, i.e., all three files listed above. Make sure your name is on all the papers you hand in!
    Bring the cover page and hardcopy to class on the day the assignment is due and deposit it in the homework box at the front of the classroom within the first 5 minutes of the class:
    cs1007-002: 11.05am
    cs1007-001: 2.45pm

points.
This assignment is worth 7 points (out of 100 for the semester). Distribution of points is: