Menu

Hey Project School Need Someone Make Outputs Work Assignment Attachment Explains Everythin Q43812268

Hey this is a project for school and I need someone to make itso the outputs work.
The assignment attachment explains everything. The code is alreadydone and it compiles, but I don’t understand how to test it to movethe Bug using the test driver as is explained in the Assignmentdocument.

class Bug {

// Variable declaration

private int position;

private String direction;

//Default Constructor

public Bug(){

position = 0;

direction = “Right”;

}

public Bug(int p, String dir){

position = p;

direction = dir;

}

public void setPosition(int p){

position = p;

}

public int getPosition(){

return position;

}

public void setDirection(String s){

if (s.equals(“Right”) || s.equals(“Left”)) {

direction = s;

}

else

System.out.println(“Invalid Direction”);

}

public String getDirection(){

return direction;

}

public void bugMovement(){

if (direction.equals(“Right”)) {

position++; // increments the position of the bug by 1

}

else if (direction.equals(“Left”)) {

position–; // decrements the position of the bug by 1

}

}

// The purpose of the method below is to ensure that thedirection of the bug is reversed.

// Meaning that, if the bug is right, change it to left, andvice versa.

public void reverseDirection(){

if (direction.equals(“Right”)) {

direction = “Left”;

}

else if (direction.equals(“Left”)) {

direction = “Right”;

}

}

// toString method to get the output in a nice way

public String toString(){

return “Bug is currently positioned at: ” + position;

}

}

Bug class above

Expert Answer


Answer to Hey this is a project for school and I need someone to make it so the outputs work. The assignment attachment explains e…

OR