Please write town and road code in java
Assignment Description In this project you will be creating an application to maintain a network of towns and the roads connecting them. The application will use Dijkstra's Shortest Path algorithm to find the shortest distance between any two towns. Upload the initial files and your working files to the repository in GitHub you created in Lab 1, in a directory named Assignment. Classes Data Element - Town (Vertex) Create a Town class that holds the name of the town and a list of adjacent towns, and other fields as desired, and the traditional methods (constructors, getters/setters, toString, etc.). It will implement the Comparable interface. This is the class header: public class Town implements Comparable
Two towns will be considered the same if their name is the same. Data Element - Road (Edge) Create a class Road that can represent the edges of a Graph of Towns. The class must implement Comparable. The class stores references to the two vertices(Town endpoints), the distance between vertices, and a name, and the traditional methods (constructors, getters/setters, toString, etc.), and a compareTe, which compares two Road objects. Since this is a undirected graph, an edge from A to B is equal to an edge from B to A. This is the class header: public class Road implements Comparable Data Structure - Graph, implements GraphInterface Create a Graph class that implements the GraphInterface given you. For Graph, V is the vertex type (a Town), E is the edge type (a Road). You will need to decide how to store the graph, use an adjacent matrix or an adjacency list. This is the class header: public class Graph implements GraphInterface Within the Graph interface is a method shortestPath, which finds the shortest path from a given source Town to a destination Town. Since there is a unique shortest path from every vertex to the source, there is a back-pointer to the previous vertex. The method shortestPath calls dijkstraShortestPath which finds the shortest path from the source to every other vertex in the graph. You will be coding the Dijkstra's Shortest Path algorithm. You will then be able to find the connections between two towns through the roads that connect them. You may use the adjacency matrix approach found in the text book, or you may use a set of Towns and a set of Roads. The ShortestPath algorithm typically uses a weighted graph which means that the edges have a weight, and this is used to determine the shortest path. For this implementation, each weight will be the distance of the road in miles. Data Manager - implements TownGraphManager Interface Your TownGraphManager will hold an object of your Graph. Implement the TownGraphManagerInterface. There are methods to populate the graph (reading from a text file), add a town (vertices), add a road (edge), list all towns and all roads, and list towns adjacent to a given town. Your solution will find the shortest path from a start town to a destination town. It will account for the possibility of a disjoint graph (i.e., not all vertices can be reached from all other vertices.) You may add any methods as needed for your design. public class Road extends java.lang. Object implements java.lang.Comparable The class Road that can represent the edges of a Graph of Towns. The class must implement Comparable. The class stores references to the two vertices(Town endpoints), the distance between vertices, and a name, and the traditional methods (constructors, getters/setters, toString, etc.), and a compare To, which compares two Road objects. Since this is a undirected graph, an edge from A to B is equal to an edge from B to A. Constructor Summary Road (Town source, Town destination, int degrees, java.lang.String name) Constructor Road (Town source, Town destination, java.lang. String name) Constructor with weight preset at 1 Method Summary intcompareTo (Road o) boolean contains (Town town) Returns true only if the edge contains the given town boolean equals(java.lang.Object r) Returns true if each of the ends of the road r is the same as the ends of this road. Town getDestination() Returns the second town on the road java.lang.String getName() Returns the road name Town getSource) Returns the first town on the road int getWeight() Returns the distance of the road java.lang.String toString() To string method. Methods inherited from class java.lang. Object getClass, hashCode, notify, notifyAll, wait, wait, wait public class Town extends java.lang.Object implements java.lang.Comparable Represents an town as a node of a graph. The Town class holds the name of the town and a list of adjacent towns, and other fields as desired, and the traditional methods (constructors, getters/setters, toString, etc.). It will implement the Comparable interface These are the minimum methods that are needed. Please feel free to add as many methods as you need. Constructor Summary Town (java.lang. String name) Constructor. Town (Town template Town) Copy constructor. Method Summary int compareTo (Town o) Compare to method bool equals(java.lang.Object obj) java.lang.String getName() Returns the town's name inthashCode) java.lang. String toString() To string method Methods inherited from class java.lang. Object getClass, notify, notifyAli, wait, wait, wait