|
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
Today we will re-visit Greenfoot's
We'll work on labs individually today, not with partners.
Hint: If you look near the top ofYou can recall the loops we wrote in yesterday's lecture.class Turtle , you can see that there is a field to keep track of eachTurtle 's direction.
Stopping when the internal angle was (360-15)° or more was kind of a yucky end-condition; initially did that because angles “wrap around” back to 0°, and we don't have a good way of telling 1° from 361°, so we needed to stop before we reached 360°.
stopping when the turtle is facing (nearly) east is also incorrect for another reason: it only draws a full circle if the turtle started by facing east. But clearly, it makes sense to make a full revolution no matter what direction the turtle starts in.
However, we can tell from the outset how many rotations we
want to make: 360°/15°.
And since we're now using an index variable, we can change our
loop to say “do the following 24 times”.
Modify
home—info—lects—labs—exams—hws
tutor/PIs—breeze (snow day)
Object120 + its docs—java.lang docs—java.util docs
©2012, Ian Barland, Radford University Last modified 2012.Nov.06 (Tue) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |