This needs to import shapes and colors as well as use a JFra

This needs to import shapes and colors; as well as use a JFrame.

This needs to be in java, have a class and a separate tester.

Write a class Bug that models a bug moving along a horitzontal line. The bug moves either to the right or left. Intiially, the bug moves to the right, but it can turn to change its direction. In each move, its poisiton changes by one unit in the current direction. Provide a constructor public Bug(int initialPosition)

And methods

Public void turn()

Public void move()

Public int getPosition()

Sample usage:

Bug bugsy = new Bug(10);

Bugsy.move(); // Now the position is II

Bugsy.turn();

Bugsy.move(); //Now the position is 10

Your BugTester should construct a bug, make it move and turn it a few times, and print the actual and expected position.

Solution

Hi

Here is the constructor for the bug movements and printing the positions of
the bug when it turns and moves .

package bug;
public class Bug {
   Public void turn()
   Public void move()
    Public int getPosition()
public static void main(String[] args) {
Bug Bugsy = new Bug(10);
Bugsy.move(); // 11th position
Bugsy.turn();
Bugsy.move(); // 10th position again
System.out.println(Bugsy.getposition());
   System.out.println(Bugsy.expectedposition(10));
}
}

This needs to import shapes and colors; as well as use a JFrame. This needs to be in java, have a class and a separate tester. Write a class Bug that models a b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site