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. For your design, create a UML Class diagram. Create a separate driver program that instantiates one or more Bug objects and demonstrates things like moving several times, then turning, then moving the same number of times (back to the original position).

Hint: 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 return the current position along with which direction the bug is facing to the driver so it can be output.

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!