Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Rat Crossing Desert Instructions Create a program that finds a path across the desert grid using rats. General behavior and specifications of program. The program
Rat Crossing Desert
Instructions
Create a program that finds a path across the desert grid using rats.
General behavior and specifications of program.
The program will consist of one static class: ControlDriver class, and five object producing classes: Desert
class, Cell class, Hole class, RatStatus class, and Rat class. There will also be a static ObjectCreator class
that I will provide.
The ObjectCreator class is a static class that will provide Desert, Rat, RatStatus, Cell, and Hole objects
when requested. Return values from these requests are interface types. The purpose of this class is to
hide the production of objects from the client classes. Client classes will only use interfaces to work with
objects.
The ControlDriver class is a static class that will
contain the main method, which is the entry point into the program.
control the timing of the rat moves.
o It will control the timing of rat movement across the desert by telling the Desert object
when a rat can move. ControlDriver will use a loop to notify the Desert to move a rat for
each move.
only communicate with the Desert and RatStatus objects through their respective interfaces.
be responsible for initiating the creation of new Rat objects.
o It will call startRat:RatStatusInterface Desert and receive back a RatStatus object that
contains the unique ID and status for the new rat.
o it will maintain a list of current rat IDs.
request the creation of the Desert object
o It will request the creation of a single Desert object by calling
ObjectCreator.createNewDesert and work through the DesertInterface of the object
in running rats through the desert grid.
The Desert will
implement the DesertInterface
create the dimensional CellInterface array for the desert during the construction of a new
Desert object.
o The Desert constructor will query the user for the size of the desert array.
o The Desert will create a twodimensional array to represent the desert. It will be of type
CellInterface and will hold Cell and Hole objects.
Cell class implements CellInterface,
call ObjectCreator.ceateNewRat to create a Rat object when prompted and return a unique ID
tuple for that Rat object RatStatus Note this is not the reference to the Rat object see
Ratstatus class
start the rat in location of the Deserts array by doing the following task.
o will hand over a Rat to a cell and remove the Rats reference from its own records.
be responsible for keeping track of the rats location and movement pathNote: You may
delegate keeping track of the rats movement path to the Rat. We will discuss this during
lecture.
The Desert, when prompted by the ControlDriver, will:
o retrieve a Rat from a cell by asking the cell if it has a Rat with a given ID It receives the
Rats reference, and the cell will set its storage of that Rats reference to null.
o prompt the rat for a move direction.
o The Desert will calculate the rats next location using the move direction provided by the
rat and the current location of the rat.
o The Desert moves the Rat one cell in the direction indicated by the rat.
o upon completion of the move, the desert will report back to the ControlDriver with the
Rats ID and state
The state is: : when the rat is waiting to move, : when the Rat is gonedied or
escaped or : When the Rat finishes the Desert.
will work with the rat object indicated by the control driver, by calling methods from the rat,
using the RatInterface. The rat is an object of the Rat class.
keep rats from falling off the edge. The rats will stay in the grid cell closest to the edge or not
move if they are at the edge, but it will still count as a move.
display the final results
o retrieve information from the cells for displaying the final results.
o Of how many Rats died of exhaustion.
o Of how many Rats disappeared down holes.
All communication with cell objects will be through the CellInterface or the HoleInterface when
needed.
The Cell class will:
implement CellInterface
store the Cells location on the grid. Do this during the constructor.
house a rat between moves by using receiveRatRat to take the rat and then store it
randomly wear down or refresh the rat.
hold rats that die in the cell.
return rats that die in the cell.
return a rat when asked, if that one is housed in it
The Hole class will:
extend Cell class
implement HoleInterface
override the receiveRat Cell method to add the ability to transport the Rat or disappear the
Rat
hold list of other holes. static Used to select which cell to transport the Rat to
contain a count of rats that disappear down its hole.
randomly transport rats to other Holesmost of the time
randomly allow rats to escapeabout of the time
return the count of rats that escapedisappear do
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