Answered step by step
Verified Expert Solution
Question
1 Approved Answer
4 . The class TrackCarver has been implemented for you. This is the main class. 5 . The class TrackGenerator needs to be implemented by
The class TrackCarver has been implemented for you. This is the main class.
The class TrackGenerator needs to be implemented by you. Specifically the following
methods need to be filled in:
private static void fillDArray char wood points
The purpose of this method is to fill the dimensional array with all one character
to represent a fresh piece of wood.
public static void carveTrackchar wood, int x int y points
This method is the recursive method. wood should already be filled with the
character that you chose to fill it with in fillDArray you dont need to call it x
and y is the location your algorithm is currently at At this point, your virtual
chisel has to check to see if it can move in any direction. Randomly chisel in a
direction provided you can see above rules This means chiseling through two
spots of the array by setting those cells to blank spaces and passing off this new
location to a recursive call of this method. When it can no longer make any moves
it has no neighbors the method simply returns.
To help with carveTrack, I have provided you with methods.
hasWestNeighbor
hasEastNeighbor
hasNorthNeighbor
hasSouthNeighbor
hasNoNeighbors
You can use these methods to help you determine if there are neighbors and which
neighbors it has. Again, neighbors are defined as a place you can chisel to that will
not chisel into an already existing tunnel.
Make sure you comment your program. This includes name, date, description, as well as
general comments in the above mentioned methods carveTrack and fillDArray
points
Test your program thoroughly with different size tracks. In TrackCarver.java, you will
see the call to printMatrix, if you replace the textfile name with an empty string it
will print the track to the console. You can do this early on to quickly test your code. The
downside is after a certain size, the console will not accurately print out the track a
limitation of the console Once you are certain your track works, print out tracks of
different sizes, and complete them with a pen or marker to show the rats can complete it
get to the cheese from the beginning Alternatively, you are granted permission to have
a friend or family member complete the printed tracks for you. NOTE: your recursive
algorithm does not need to make the start and end points, you can manually choose
them when you go to print it Scan or take pictures of the completed tracks.
import java.ioFile;
import java.ioPrintWriter;
import java.util.Random;
public class TrackGenerator
private static Random rand new Random;
private static void fillDArraychar wood
Fill the D array 'wood' with nonspace characters
TODO FILL IN CODE HERE
private static void carveTrackchar wood, int x int y
TODO FILL IN CODE HERE
private static boolean hasWestNeighborchar wood, int x int y
return x && woodxy;
private static boolean hasEastNeighborchar wood, int x int y
return x && woodxy;
private static boolean hasSouthNeighborchar wood, int x int y
return y
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