Project #3
(Map Folding)
(Due 28 Feb 07)
Places Inc. wants a new program for their road map folding machine. You are being asked to write this program and to create a class which can be used to simulate the folding machine's operations. In this way, you can test your map folding program on the simulated machine before trying it out on the real thing.
The map folding machine is capable of four, and only four, actions. These are specified to you in the MapFolder interface which is given below. It is assumed that any class which implements the MapFolder interface has an instance variable that represents a road map. All road maps are a multiple of 4 inches in length and a multiple of 9 inches in width. The job of the map folding machine is to fold the map into a 4x9 rectangle with the cover page on the top.
public interface MapFolder {
// Load a map into the map folding machine.
Each map is between 28 and 48
// inches in length and between 9 and
36 inches in width. Initially, the
// cover page for the map may be in any
of the four corners and may be on
// the "above" surface or on the "below"
surface
public void loader ();
// A map must be "fan" folded (or "accordion"
folded). A side fold is
// done along the entire width, 4 inches
at a time, starting from the right
// side of the map. A fold may be
"over" in which case 4-inches of the map
// is folded up and over; or it may be
"under" in which case 4-inches is
// folded down and under. The direction
must be either "over" or "under".
public void sideFold (String direction);
// A map may also be folded along the
entire length, 9 inches at a time,
// starting at the top of the map - this
is a top fold. A top fold may be
// "over" in which case 9-inches of the
map is folded up and over; or it
// may be "under" in which 9-inches
may be folded down and under. The
// direction must be either "over" or
"under".
public void topFold (String direction);
// After a map is completely folded, the
map folding machine places it on
// a stack of finished maps. The
folding technique may be such that when
// the folded map is a 4x9 rectangle,
the cover may be above or below. If
// the cover is above, the folding machine
just places it on the stack.
// If the cover is below, the folding
machine flips it over before placing
// it on the stack.
public void stackIt ();
}
Your program must include this interface; you can find a copy at I:\jlwolfe\310\s07\MapFolder.java A file named maps.txt contains the specification for twenty-five maps. You can get a copy of this file from the folder I:\jlwolfe\310\s07\maps.txt Each of the map specifications appear on one line, in the form:
length width cover-position
The length is a multiple of 4 and is at least 28; it is measured horizontally. The width is a multiple of 9 and is at least 9; it is measured vertically. The cover position consists of three words separated by spaces: the first word is either left or right to indicate the horizontal end that the cover is on; the second word is either top or bottom to indicate the vertical end the cover is on; and the third word is either above or below to indicate which surface the cover is on.
Your application is to use the loader() method to acquire a map object to be used in the folding process. The map object must be created based on the specification of one line of the maps.txt file. The program must then fold the map (in "fan" fold form) and place it into the stack with the cover on the top; this must be done using the sideFold(String), topFold(String) and stackIt() methods. The program should document its actions by listing the folds needed to get the map into the proper form and should display any flipping action that the map folding machine would take before putting the map into the stack. To document these actions, I recommend displaying "s.over" or "s.under" (or possibly "side-over" and "side-under) to show a side (horizontal) fold and its direction, displaying "t.over" or "t.under" (or possibly "top-over" and "top-under") to show a top (vertical) fold and its direction, and displaying "adjust" or "flip" if it is needed for the stack.
You must have a class that implements the MapFolder interface - this simulates the folding machine capabilities. You may not change any of the methods for this interface or add any methods to the class that implements the interface (other than constructors and/or Getters and Setters). In addition, I recommend having a class to represent a map and an application class. There is at least one other class you might have; but I will let you decide about that.
For each map specification read, display it's specification (what was read from the file) before starting to fold. Then display the folding actions. Here is a sample, based on the first two maps in map.txt
Length: 40 Width: 18 Position: left bottom above
Folds: s.under s.over s.under s.over s.under s.over s.under s.over
s.under t.under
Length: 32 Width: 36 Position: right top below
Folds: s.over s.under s.over s.under s.over s.under s.over t.under
t.over t.under
Flip to stack
Hand in a well-documented printout
of your program (.java files) and a printout of the output from folding
the twenty-five maps. Also, copy the .java files you made for this
project to a folder named p3 under the folder named after you on
the P: drive for this course.