When working with labyrinths and hexagons, there are two situations that come up
ID: 3911757 • Letter: W
Question
When working with labyrinths and hexagons, there are two situations that come up.
1. UnknownLabyrinthCharacterException a. As you can see in the Labyrinth file, the constructor may throw this exception while reading the file describing the labyrinth.
2. InvalidNeighbourIndexException a. This is to cover the case where an entity requests a neighbour that is not 0-5 inclusive. Y
our task is to create these two exceptions as .java files. Take a look at the EmptyCollectionException to get an idea of what this would look like.
*****Labyrinth.java******
****Hexagon.java****
Explanation / Answer
The required Custom Exception classes are given below in table. Please create 2 java files with the same name as that of the Exception class names into the same project where the above project files exist and save. Finally, test the program running them.
public class UnknownLabyrinthCharacterException extends Exception{
public UnknownLabyrinthCharacterException(char ch)
{
super("Unknown Labryinth character '" + ch + "' found");
}
public UnknownLabyrinthCharacterException()
{
}
}
public class InvalidNeighbourIndexException extends Exception{
public InvalidNeighbourIndexException(String msg)
{
super(msg);
}
public InvalidNeighbourIndexException()
{
super("Neighbhour out of range requested. Valid neighbhours must be in range 0 - 5");
}
}
UnknownLabyrinthCharacterException.javapublic class UnknownLabyrinthCharacterException extends Exception{
public UnknownLabyrinthCharacterException(char ch)
{
super("Unknown Labryinth character '" + ch + "' found");
}
public UnknownLabyrinthCharacterException()
{
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.