Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Hey this is a project for school and I need someone to make it so the outputs work. The assignment attachment explains everything. The code is already done and it compiles, but I don't understand how to test it to move the Bug using the test driver as is explained in the Assignment document.

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 the direction of the bug is reversed.

// Meaning that, if the bug is right, change it to left, and vice 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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions