|
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
Do problem P3.10 (Moths) from the textbook.
Note that there is a typo in the signature provided for
getPosition;
that method should return the moth's current location.
Also, write a method distanceToLight, which is given the position of a light, and returns the (full) distance between the light and the Moth. It doesn't change the Moth's position. As usual, complete the following steps in order:
Further practice, if you finish:
Add test cases, signature, and code for
a method moveAgain.
The method
takes no inputs, and has the Moth move towards the light's
last known location.
The “last known location” initially starts as 0.0
(and is updated every time moveToLight
or distanceToLight is called).
You might also make a second version of distanceToLight which takes no inputs, and returns the distance to the light's last known location.
home—info—lects—labs—exams—hws
textbook—tutor/PIs—java.lang docs—java.util docs
©2009, Ian Barland, Radford University Last modified 2009.Feb.16 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarlandradford.edu |