Exercise
10/02/2006
|
Surround a Box
|
Due: Monday, October 9 8am
|
Relevant Reading:
- Handout from class (not available on line) and class notes
- By now, you should have read Chapters 1,2,3,5, and 6 of Karel J Robot.
- Skim Chapters 1 and 3 of Head First Java. Also, Chapter 5, pages 105-112 has some potentially useful stuff at this
point, too. However, it relies on some stuff we have not done yet.
- Other readings in other references you may have (eg. the Pohl download)
Assignment: (worth 10 exercise points)
Get the ex10-02.zip file. Use the
files
in this folder as your basis for this assignment.
In this
assignment, you will explore a common theme in computing. 1)
Determine what resources you need; 2) obtain those
resources if possible; 3) distribute the resources.
In the lower corner of the world (1,1), there is a pile of 1000
beepers for
your task. The world displays may not show 1000 beepers, but
they are there. This is due to display problems with fitting the
number 1000 in a small circle.
Between the third and fourth rows of the world, is the
bottom of a box, of unknown width and height. Sample worlds are
box1,
box2, box3, box4, and box5.
You are given an Application class that has a robot go count the
intersections around the box in box1.txt. A second robot puts 2
beepers on each of those intersections.
Your tasks:
1) Create the BoxRobot class so that the program
works. Note that there are two different constructors for the
class. (You should not need to modify Application.java for this
step.) Before and after pictures are below.
BEFORE:
|
AFTER:
|
|
|
2) Modify the program so that it asks the user for the
name of the file, and the program puts 2 beepers on each intersection
around the box in ANY world that meets the specifications. Be
sure to try all 5 possibilities. This step will likely require
modifications to both Application and BoxRobot.
3) Modify the program so that it asks the user for a
number (which I will call pilesize for these
instructions). Get the program to put that many beepers on
each of the intersections around the box, IF there are enough
beepers. If there aren't enough beepers, a second robot should
not even appear. This step may only require modification to
Application.
Notes:
- Any leftover beepers should be at (1,1) at the end.
- Be sure to modify the comments as appropriate.
- The robot must get it's beepers from the world and not start out
with any in its bag.
- Be
sure to make good utilizations of new methods, predicates, or other
methods that return a value. Each of your methods should be
relatively short.
- If you wrote the code in the first step and
second step well, the third step should only require
modifications to Application.java.
Remember:
- In the comment at the top of each file that you create or modify,
be sure to put your name.
- Each method you write should have a comment that says
what the
instruction does.
- At
the top of .java file with your new subclass(es), you should briefly
describe in the top comment what the overall new behaviors are.
- You are permitted to talk with others in this section
regarding
how the program works. However, you need to do the actual work
yourself
and understand the answer that you produce.
Handin:
-
Be sure to read the general handin instructions on the exercises page.
-
Rename the folder containing all of the files to be
"lastname-firstname-100SectionLetter-surround". For example, if I were in Section Z, I would rename my folder to
be: "McElfresh-Scott-100Z-surround"
(without the quotes).
- Create a zip file of this folder, with the same name as the folder (except
with the .zip ending this time). Instructions for zipping can be found in
the system and software handouts linked on the main course page.
- Submit this file via the electronic
handin. If you have problems, contact me.
|