Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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

ID: 3790096 • Letter: T

Question

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.

Explanation / Answer

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));
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote