|
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
We'll briefly introduce the notion of rooms connected to each other (a “graph”), which you'll implement in hw14 with a Room method connectTo(Room). You can have
Exercise: create a Room named “bottomless pit”, which is connected to itself.
Exercise: Create 3 Rooms, each named "deep pit", each connected to the next, connected (in turn) to a Room "the bottom". solution
Exercise: Create 1000 Rooms, each named "nearly bottomless pit", each connected to the next, except the last, which is connected to a Room named "Center of the Earth".
Hint: When you've done 500 rooms, what value/information will you have accumulated? How will you adjust this information, the 501st time through the loop?
Hint (less obvious): create the rooms from the bottom up, starting with the bottom of the pit: solution
Creating the same rooms working from the top down takes an extra step of work, you can see when you work through it by hand:
Actually make this a function that can be called as needed: solution
home—info—exams—lectures—labs—hws
Recipe—Laws—lies—syntax—java.lang docs—java.util docs
©2007, Ian Barland, Radford University Last modified 2007.Nov.26 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |