CS1007
Fall 2001
Homework #3
due Tuesday 16 October 2001

last updated: Wed Oct 10 22:59:08 EDT 2001 / eis

please... complete the on-line Midterm Course evaluation here: http://www.esurveys.columbia.edu/wces/.

goal... The goal of this assignment is to practice using loops, ASCII graphics and two-dimensional arrays.

create... a Java application program that stores a representation of a rectangular soccer field in a 2-dimensional array, reads two pairs of coordinates from the command line (representing the locations of a robot and a soccer ball within the soccer field), marks those coordinates on the soccer field and prints out the field.

Here's an illustration of the field:

(0,9)                                 (39,9)
  +--------------------------------------+
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |        o                             |
  |R                                     |
  |                                      |
  +--------------------------------------+
(0,0)                                 (39,0)
The field is represented as a 2-dimensional character array, with 10 rows and 40 columns. The field represents only quadrant I of a Cartesian grid, which means that the lower left corner is (0,0). As marked, the upper left corner is (0,9), the upper right corner is (39,9) and the lower right corner is (39,0).

1. initialize the field... Initialize the field by storing blank spaces in all entries except the edges, as shown in the illustration, above. The corners should be marked with '+' characters. The northern and southern (horizontal) edges should be marked with '-' characters. The eastern and western (vertical) edges should be marked with '|' characters.

2. process input... As with hw2, the two input pairs of coordinates should be entered on the command line and converted from String to int. For example:
unix$ java hw3eis2003 1 2 9 3
would mean that the robot is at location (1,2) and the ball is at location (9,3).

3. check input... The program should first check that four numbers were entered on the command line. If not, then the program should print a usage error and exit.
Next, the program should make sure that the coordinates entered are valid. For this homework, the representation (above) means that no negative values are allowed. Additionally, values of 0 are not allowed because those represent the western and southern edges of the field. Similarly, x values must be less than 39, since 39 is the x-coordinate of the eastern edge of the field; and y values must be less than 9, since 9 is the y-coordinate of the northern edge of the field. If any of the coordinates entered on the command line are out of range, then the program should print a usage error and exit.

4. echo input... If the input coordinates are deemed okay, then the program should echo them to the screen. For example, given the command line input (above), the output would be:
robot is at position (1,2)
ball is at position (9,3)

5. plot locations... The program should next plot (i.e., mark) the locations of the robot and the ball on the soccer field, by storing an 'R' in the 2-dimensional field array for the robot's location and an 'o' in the 2-dimensional field array for the ball's location. If the robot and the ball are in the same location, then mark the field with an '*'.

6. print field... The program should finally print out the field, with the robot and ball marked, as well as the edges and corners, as above.

Here's a sample run:
unix$ java hw3eis2003 1 2 9 3
robot is at position (1,2)
ball is at position (9,3)

  +--------------------------------------+
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |                                      |
  |        o                             |
  |R                                     |
  |                                      |
  +--------------------------------------+

7. submit... Your program file MUST be named hw3<yourCUNIXusername>.java. For example, mine would be called hw3eis2003.java. BE SURE TO NAME YOUR FILE USING ALL lower case LETTERS!!!
Submit your program in two ways: electronically and hard copy. Check the assignments link on the class home page for submission instructions.