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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started