Question: Implement a class Moth that models a moth flying in a straight line. The moth has a position, the distance from a fixed origin. When
Implement a class Moth that models a moth flying in a straight line. The moth has a position, 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. Supply a constructor
public Moth(double initialPosition) and methods
• public void moveToLight(double lightPosition)
• public void getPosition()
Your main method should construct a moth, move it toward a couple of light sources, and check that the moth’s position is as expected.
Step by Step Solution
3.39 Rating (165 Votes )
There are 3 Steps involved in it
Solution I... View full answer
Get step-by-step solutions from verified subject matter experts
