The design of classes is up to you, but you do need to implement certain classes to represent certain entities in the program. You need to make decisions about how to design these classes to produce an efficient and well-put-together program. Make sure that all methods that you include in a particular class belong to that class. Java is an object-oriented programming language and your programs should follow object-oriented principles.
MountainClimb
class
This is the class that is the program. This means it has the main
method. This class is responsible for parsing and validating the command line arguments, reading and parsing the input file, producing any error messages, handling any exceptions thrown by other classes, and producing output.
BST<E>
class
This is a generic BST<E>
class. The specification is similar to the one for TreeSet
class provided by Java libraries, but your implementation will be very different.
The specification for this class is provided at its javadoc page. You can use the source code we wrote in class, but keep in mind that the class you are implementing requires additional functionality and you may need to rewrite some of the methods created in class.
Node
class
The program should provide and use a nested class (to learn more about nested and inner classes see: https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html) that provides nodes for your tree. The details of the implementation of that class are up to you, but this class should be private (or protected, if another class in your code inherits from it and needs to be able to create variables of type Node
):
HINT: to improve the performance of your BST algorithms, it may be useful to keep additional data fields in the nodes, i.e., more than just data, left and right. Those design decisions are up to you. But you should explain in comments for this class, why you have additional data fields if you chose to do so.
Iterator
The BST<E>
class implements Iterable<E>
interface. This means that its iterator()
method needs to return an instance of a class that implements the Iterator<E>
interface. The iterator()
method should return an iterator instance that accesses the values in the tree according to the inorder traversal of the binary search tree. The two additional methods preorderIterator()
and postOrederIterator()
need to return iterators that access the values in the tree according to the preorder and postorder traversals, respectively.
The implementation details are up to you and you are free to implement more than one internal private iterator class. The next()
and hasNext()
methods of the iterator classes should perform in O(1). The constructor of the iterator classes can be O(N). You are not allowed to use the implementation of iterators of any built-in classes when writing your implementation of the iterators.
The remove method in the Iterator<E>
interface is optional and you do not need to provide the actual remove functionality. (This means that the method has to exist, but instead of performing its function, it throws an instance of UnsopportedOperationException
.)
NOTE: normally, all data fields in the class should be private. However since the BST
class serves as a base class for the BSTMountain
class below, its data fields can be made protected instead to allow the subclass to access these data fields.
BSTMountain
class
This should be the class that inherits from your own BST<RestStop>
. Your class should represent the mountain itself (therefore, it should not be generic and its nodes should store data items of type RestStop
). It is up to you to decide how to implement this class, which methods to provide etc. Hint: this class should implement methods that allow a hiker to explore the mountain. The reason for that is that the exploration algorithm is specific to the mountain itself, not to the hiker (any Hiker
object will follow the same steps when traveling down the same mountain). The exploration of the mountain is the process of figuring out which paths lead safely from the top of the mountain to its bottom (lowest level) with sufficient supplies for the hiker to survive.
RestStop
class
This class should represent a single rest stop. It should be capable of storing the label of the rest stop along with a list of the supplies that a hiker can collect at this rest stop and a list of obstacles that a hiker may encounter at this rest stop. It may be useful (or necessary) to implement the Comparable
interface.
Hiker
class
This class should represent a hiker traveling down the mountain. An object of this class should be capable of keeping track of all the supplies that the hiker has in their possession. This information should be updated as the hiker travels along a trail and consumes supplies (by either eating along the way or using the tools to clear the path or cross the river).
You may, but you are not required to, implement other classes.