CS1007
Fall 2002
Homework #3
due Thu Oct 17, by 6AM -- electronic submission

hardcopy due IN CLASS by 2.45PM

goal.
The goals of this assignment are to learn how to:

  1. write pseudo code and create a flowchart;
  2. use 2-dimensional arrays;
  3. get keyboard input;
  4. write your own methods and call them.

overview.
You have a robot that is roaming around an enclosed soccer field. You can send it commands (up, down, left, right) to get it to move up, down, left or right. The soccer field is represented by a rectangular grid, and with each command, the robot will move one square in the grid. Your program should accept commands from the user and process them until the user indicates s/he wants to quit the program.

design.
You need to create and submit some design documentation, as follows:

  1. You must store the soccer field in a 2-dimensional array, so first you need to figure out how you are going to do that. All the elements in the array will store '.' characters, except the location of the robot will store 'R'.
  2. Then you need to design the way your program works. Write down a list of the processing steps in pseudo code, as discussed in class. You need to turn in the pseudo code as part of your assignment. (0.5 points)
  3. Next, figure out which steps best belong in a method and which steps belong in main().
  4. Then draw a flowchart diagramming the user interactions and the processing steps, indicating where each method will be called. You need to turn in the flowchart as part of your assignment. (0.5 points)

program.
You need to write methods to do the following:

  1. clear the field by storing the '.' character in all the array elements (1 point)
  2. mark one element in the field (with a 'R') to indicate where the robot is (0.5 points)
  3. print out the field on the screen (1 point)

example.
Here's a sample run:

unix$ java hw3eis2003
here is the field:
/=====\
|.....|
|.....|
|..R..|
|.....|
|.....|
\=====/
how would you like to move (u=up,d=down,l=left,r=right,q=quit): u
here is the field:
/=====\
|.....|
|..R..|
|.....|
|.....|
|.....|
\=====/
how would you like to move (u=up,d=down,l=left,r=right,q=quit): q
unix$

hints.

  1. You only need to store the '.' and the 'R'. You don't need to store the field borders, as shown in the example. You can print borders if you want, or you can just print a square of dots, without borders.
  2. You must check to make sure that the robot doesn't run off the edge of the field.
  3. You must report an error if the user enters an invalid command.

source code.
Your program file MUST be named hw3<yourCUNIXusername>.java
Your source code must be neat and clearly commented. You must have a header comment and you should comment the end of each block (i.e., each }).

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 file properly.
    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!!!

  2. Submit your program electronically.
    Follow instructions on the assignments page.

  3. Turn in a hardcopy 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 source code.
    You also need to turn in the pseudo code and flowchart. Handwritten diagrams are fine.
    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.

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