See part C of this page for the window counting robot.
We can identify three classes here: Room, Window, and Bot. The suggested specs for each class are below, but feel free to make your own version.
1. Room:
private int height; // vertical measurement
private int width; // horizontal measurement
Room(int height, int width) { // constructor details to be filled}
public int getHeight();
public int getWidth();
2. Window:
private int locationX; // upper left corner is (0,0)
private int locationY; // upper left corner is (0,0)
Window( int x, int y){ // constructor details to be filled}
/* Install a window randomly on a wall, based on the room dimension of course
* Window size = 1, but since windows are randomly put, there is a chance they may be next
* to each other. In this case, they are counted individually. Similarly, windows wrapping
* around a corner are counted individually too. (You are challenged to provide a method to
* "merge" these windows as one) */
private void windowInstallation()
3. Bot:
private int id;
private int initialX;
private int initialY;
private int initialOrientation; // feel free to use different types
// constructor details to be filled, feel free to implement multiple as you see necessary
Bot(){ }
private move() {details to be filled} // move forward ONLY
private turn() {details to be filled} // turn to change orientations
private sense() {details to be filled} // sense
/* method below should return the total windows found by "this Bot"
* this method may call the three "helper" methods above to finish counting
* the three methods above are declared as private cause they should only be called
* internally by this method */
public int windowHunting() {details to be filled}
4. Tester:
1) Ask the user to specify room dimensions as input, construct a room accordingly;
2) Generate a random number of windows, and install them randomly on each wall; Of course the larger the room, the more windows you may install, but the total windows should be limited by the room sizes;
3) Print out the room layout with windows installed;
4) Ask the user to specify the location and orientation of the bot (see legends below);
5) Construct the bot accordingly, (optionally) print out the room again with the bot;
6) Print out the moving path of the bot in order to count all windows, the total windows found, and the number of windows on each wall.
5. Legends:
1) Use "[ ]" for one floor unit, use "++" for one window. Use "vv" (letter v) for one downward bot, "^^" for the upward bot, "<<" and ">>" for the side facing bot accordingly. When the bot turns, the symbol should update accordingly.
2) We use two letters for each "unit" to assure the output is a square instead of a rectangle. See my sample below.
What does j%5==2 mean again?
Below is a sample printout for your reference. Here are the code if you want to test it out:
for(int i=0;i<20;i++){
for (int j=0;j<20;j++){
if((i==0 && j%5==2) || (j==0 && i%13==1) || (i==19 && j%7==4) ||(j==19 && i%7==2)){
System.out.print("++");
}else if (i==9 && j==8){
System.out.print("VV");
}else
System.out.print("[]");
}
System.out.println();
}