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; north → west → south → east → north). In each move, its position changes by one unit in the current direction. Details of the "Bug" class is described below.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

The output should be a text file with the final position and the facing direction (no GUI required) 

Sample input/output files:
Bugs.txt - Notepad
100
100
SOUTH
186
153
NORTH
127
121
SOUTH
135
36
EAST
90
104
145
NORTH
88
WEST
21
49
17
SOUTH
45
WEST
138
81
SOUTH
120
76
NORTH
157
101
WEST
81
150
EAST
148
95
EAST
183
113
WEST
130
8
SOUTH
38
125
EAST
124
10
WEST
58
128
WEST
138
11
EAST
146
123
SOUTH
118
46
118
123
EAST
4
NORTH
65
NORTH
187
39
WEST
107
19
EAST
30
127
NORTH
140
SOUTH
163
147
182
NORTH
103
SOUTH
45
114
EAST
123
118
EAST
167
113
NORTH
132
63
NORTH
163
150
WEST
2
117
95
162
WEST
139
EAST
82
WEST
172
130
EAST
102
25
NORTH
71
90
145
NORTH
95
SOUTH
171
21
NORTH
198
127
NORTH
29
120
NORTH
127
163
WEST
157
8
NORTH
4
178
SOUTH
112
185
SOUTH
144
49
EAST
Figure 2 Sample input file
Transcribed Image Text:Sample input/output files: Bugs.txt - Notepad 100 100 SOUTH 186 153 NORTH 127 121 SOUTH 135 36 EAST 90 104 145 NORTH 88 WEST 21 49 17 SOUTH 45 WEST 138 81 SOUTH 120 76 NORTH 157 101 WEST 81 150 EAST 148 95 EAST 183 113 WEST 130 8 SOUTH 38 125 EAST 124 10 WEST 58 128 WEST 138 11 EAST 146 123 SOUTH 118 46 118 123 EAST 4 NORTH 65 NORTH 187 39 WEST 107 19 EAST 30 127 NORTH 140 SOUTH 163 147 182 NORTH 103 SOUTH 45 114 EAST 123 118 EAST 167 113 NORTH 132 63 NORTH 163 150 WEST 2 117 95 162 WEST 139 EAST 82 WEST 172 130 EAST 102 25 NORTH 71 90 145 NORTH 95 SOUTH 171 21 NORTH 198 127 NORTH 29 120 NORTH 127 163 WEST 157 8 NORTH 4 178 SOUTH 112 185 SOUTH 144 49 EAST Figure 2 Sample input file
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; north → west → south → east → 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.
Bug Simulator
Bug Simulator
O X
Bug Simulator
Original positions
Possible Cluster sample-1 Possible Cluster sample-2
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-I00". 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
לל
XXX
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.
Transcribed Image Text: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; north → west → south → east → 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. Bug Simulator Bug Simulator O X Bug Simulator Original positions Possible Cluster sample-1 Possible Cluster sample-2 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-I00". 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 לל XXX 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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education