Question: Java Design and implement a class called Bug, which represents a bug moving along a horizontal wire. The bug can only move in one direction

Java

Design and implement a class called Bug, which represents a bug moving along a horizontal wire. The bug can only move in one direction for one unit of distance at a time. The bug can also turn to reverse direction. Create a driver program that instantiates several Bug objects and demonstrates things like moving several times, then turning, then moving the same number of times (back to the original position).

Hints: Remember that a horizontal line has a zero position in the middle with positive to the right and negative to the left. Consider that a bug will land on the wire at some point before moving along the wire. Bug will require a toString method to output the current position and direction the bug is facing.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!