1) Implement a class Moth that models a moth flying along a straight line. The moth has a position, which is the distance from a fixed origin. When the moth moves toward a point of light, its new position is halfway between its old position and the position of the light source. Find the instance variable(s), define and implement the constructor(s), then supply the following methods: - public void moveToLight(double lightPosition) - public double getPosition()
1) Implement a class Moth that models a moth flying along a straight line. The moth has
a position, which is the distance from a fixed origin. When the moth moves toward a
point of light, its new position is halfway between its old position and the position of
the light source. Find the instance variable(s), define and implement the constructor(s), then supply
the following methods:
- public void moveToLight(double lightPosition)
- public double getPosition()
2) Document your class, generate Javadoc documentation and produce a test
that construct a moth, move it toward a couple of light sources, and check that the moth’s position
is as expected.
3) Add a comment to your class Moth that explains how you can make the Moth immobile after 10
moves.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps