Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem: Bugs are simple creatures that only know how to walk towards other bugs. Bugs maintain information about their (x, y) position; by which it

image text in transcribed
image text in transcribed
image text in transcribed
Problem: Bugs are simple creatures that only know how to walk towards other bugs. Bugs maintain information about their (x, y) position; by which it can tell if they are standing next to other bugs. Watch the following video: bug movement. Create a java project that simulate bugs movement. You need to write a class "Bug" that models a bug moving along a straight line and it can turn to change its direction counterclockwise (i.e. 90 degree to the left; northwest southeast north). In each move, its position changes by one unit in the current direction. Details of the Bug" class is described below. Your simulator should read information of an unknown number of Bug" objects from an input file called "Bugs.txt". Each line represents a bug and the initial position and facing direction of this particular bug. Keeping the first bug position as a reference the simulator should move the second bug next to the first bug forming a cluster and its final position and direction should be stored into a list. The simulator should then read the third bug and moves it towards either the first or the second bug, then add its information to the list. The consequent bugs should move next to any bug in the list (i.e. randomly selected), as soon as it join the cluster its information should be stored in the list. This process should continue until no bugs remain. Notice that at the end each bug has its unique position; i.e. no two bugs can stand at exactly the same (x, y) position. When a bug starts moving, the simulator should randomly select its path vertically or horizontally towards the cluster. This results different possible bug cluster shapes each time you run the simulator. See the figure 1 below as an example of bug movement simulator resulting a cluster. x a X time- Original positions Possible Cluster sample-1 Possible Cluster sample-2 1 Figure 1 Example of bug movement simulator forming a cluster As soon as the final cluster is formed, your program should display the details of the bug available in the simulator in an output file BugsSimulator.txt". Figure 2 and 3 shows a sample input file and the corresponding possible output files forming different clusters. Bug Class: a bug has a code, original location at a point with integer coordinates, faces north, east, south, or west and keeps a record of all its current movement position. The class generate a unique code for each new "bug" object created starting with value "b-100. It also includes the following methods: A default constructor that initializes bug's code to "b-xxx; where xxx is the next code sequence number in the class, positions to (0,0), and direction to WEST. A constructor that is given bug's information: starting location, facing direction and generates bug code similarly to the default constructor. Accessor methods to access all the instance variables and the simulated movements of the bug. Mutator methods that change the instance variables to given values and they make the change for only suitable values. turn method that changes the direction of the bug counterclockwise. move method that moves the bug by one unit in the direction it is facing. 100 186 127 135 90 104 21 49 138 120 157 81 148 183 130 38 124 58 138 146 118 46 118 187 107 30 140 163 147 45 123 167 132 163 2 117 95 172 102 71 90 171 198 29 127 157 4 112 144 178 100 153 121 36 145 88 17 45 81 76 101 150 95 113 8 125 10 128 11 123 123 4 65 39 19 127 9 182 103 114 118 113 63 150 162 139 82 130 25 145 95 21 127 120 163 8 178 185 49 80 SOUTH NORTH SOUTH EAST NORTH WEST SOUTH WEST SOUTH NORTH WEST EAST EAST WEST SOUTH EAST ST WEST EAST SOUTH EAST NORTH NORTH WEST EAST NORTH SOUTH NORTH SOUTH EAST EAST NORTH NORTH WEST WEST EAST WEST EAST NORTH NORTH SOUTH NORTH NORTH NORTH WEST NORTH SOUTH SOUTH EAST NORTH

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

More Books

Students also viewed these Databases questions

Question

Explain the steps an entrepreneur goes through to buy a franchise.

Answered: 1 week ago