Due Dates:
This assignment is an application of queues and deques. Use your classes from the previous assignment, or if those don’t work, use the solutions provided to that assignment.
Requirement: Implement in Java the Double-Ended
Spam-Eater, the basis for a graphic application to be described in the next
assignment, its environment, and a main program controlling its actions, as
described below.
A Double-Ended Spam-Cruncher (DESC) is an artificial life form that lives on a two-dimensional grid of squares, with the following additional properties:
The purpose of this assignment is to program the class DESC and the class Grid, as well as a main program for a DESC, described next.
Requirement for the main
program:
The main program reads a grid from the standard input (System.in). The size of the grid (number of rows then columns) is read first, followed by the coordinates of the spam (row then column) until the end of file. If any row or column is out of range, the pair should be simply ignored.
The DESC always begins occupying the leftmost two squares in
the top row. It should be assumed that these squares do not contain spam. Spam
should not be specified in the input for either of those squares; if it is, it
will be ignored.
The DESC repeats the following cycle, until there is no more spam on the grid, or until the DESC has gotten itself into a position where the search can no longer reach any spam from either head in its current position:
Below observe several snapshots of the main program.
1. The first snapshot shows the start, with the DESC represented by o’s in the upper-left and the spam represented by x’s.oo x x x x |
2. The DESC turns toward the nearest spam:o x o x x x |
||
|
|
||
3. The DESC crunches the spam:o x o o x x |
4. The DESC turns toward the next nearest spam:x o oo x x |
||
|
|
||
5. The DESC crunches the next spam:x oooo x |
6. The DESC, having reversed direction, turns toward the next spam:x ooo o x |
||
Sample input and output files will be provided in the directory
/cs/cs60/a/06/.You should submit your rex functions in two files: Quantity.java and OpenList.java using
cs60submit DESC.java Grid.java . . .
where . . . represents any other support .java files needed. Do NOT submit .class files or test files.