Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Can you answer the following using Java. I included some of the code template to begin with: We ll build a program that can read
Can you answer the following using Java. I included some of the code template to begin with:
Well build a program that can read a dimensional cave layout from a file, search the layout to find a path to a mirror pool, then print the path to take. This unit, you will build the infrastructure for this project, including storing data in a two dimensional structure, searching the data structure for a simple path from start to finish and reading data from a text file. Do not use recursion or backtracking for this part.
Directions Write a class CaveExplorer, that has the following methods:
Constructor with no parameters. It should create the twodimensional structure shown below, where the characters in the layout are R for rock, for a clear path, M for mirror pool, and S for self. This constructor hardcodes the cave without reading from a file.
RRRRRR
RSRR
RRRRR
RMRRR
RRRRRR
toString no parameters, returns a string including new lines showing the current state of the cave exploration. For the initial configuration, this string would be
RRRRRR
RSRR
RRRRR
RMRRR
RRRRRR
solve no parameters, returns a boolean true if there is a path to the mirror pool, and false if there is not.
getPath no parameters, returns a String showing the path taken to get to the mirror pool. In the example, this path would be the string of directions wwsse for West, West, South, South, East. The method should return the empty string if there is no path.
Constructor with one String parameter the name of a text file with the cave layout. The file has a line with two integers, the number of rows and columns of the cave layout, followed by the layout itself. For example:
RRRRRR
RSRR
RRRRR
RMRRR
RRRRRR
Your cave layout should contain a path requiring at least moves in two different directions. There must be exactly one path through the cave, that is from any location, there is only at most one location to move to next that hasn't already been visited.
main test your class by writing a main method that creates at least CaveExplorer objects, solves each one, then prints the starting layout, the final layout, and the path taken, if it exists, for each one.
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