Question: Write a class RaceWalker that models a race walker moving along a horizontal line. The race walker moves either to the right or left. Initially,
Write a class RaceWalker that models a race walker moving along a horizontal line. The race walker moves either to the right or left. Initially, the race walker moves to the right, but it can turn to change its direction. In each move, its position changes by one unit in the current direction. Provide a constructor: public RaceWalker(int initialPosition) and methods: public void turn() public void move() public int getPosition() Sample usage: RaceWalker rw = new RaceWalker(10) rw.move(); // now is at position 11 rw.turn(); rw.move(); // now is at position 10
Your RaceWalkterTester should construct a race walker, make it move and turn a few times, and print the actual and expected position.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
