Programming in Alice & Java

advertisement
Programming in Alice & Java
Project 7.1
Mrs. Pretz
We will do Exercise 1 in class then you will do Exercise 2 on your own.
Exercise 1: lightAllCandles
In this exercise, the robot initially finds itself on a map like the one shown in the example
below.
Write the lightAllCandles method, which should darken the square on top of each "candle"
(those columns consisting of 1 or 2 walls). After calling the lightAllCandles method on the
example shown above, the map should appear as follows:
You should assume that the robot will always start in the same position, facing the same
direction, in the same size map, with the same number of candles appearing in the same
locations. The only variation will be in the heights of the candles (1 or 2 squares).
Be sure to test your code on both "candles1.txt" and "candles2.txt.
You will need to write several methods for this problem.
Exercise 2: completeRoom
In this exercise, the robot initially finds itself in a square-shaped room, like the one shown in
the example on the left below.
Write the completeRoom method, which should complete the border of the room by darkening
each cell where a wall appears to be missing. Of course, if the cell is already dark, then that
cell should remain dark. After calling the completeRoom method on the example shown on the
left above, the room should appear like the example on the right above.
You should assume that the robot will always start in the same position, facing the same
direction, in the same size room.
You will need to write several methods for this project.
Hint: If you're stuck, try solving the problem for the case where there are no cells that are
already dark. Then modify your code to handle the case where some cells may already be dark.
Be sure to test your code on both "room1.txt" and "room2.txt".
When completed you will turn in a printout of your Karl1 file and a PrintScreen picture of the
completed robot scenes. These should be stapled to the grading rubric.
Name ___________________________________
Programming in Alice & Java
Project 7.1
Grading Rubric
Use of existing methods (5 points)
____________
New methods (5 points)
____________
Comments (3 points)
____________
Use of if/else statements (3 points)
____________
Pictures of finished grids (2 points)
____________
Printout of program (Karl1) (1 point)
____________
Grading Rubric (1 point)
____________
Total (20 points)
_________________
Download