Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
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. You may add any methods as needed for your design.
-----------------------------------------------------------------------------
import java.util.*; public interface TownGraphManagerInterface { /** * Adds a road with 2 towns and a road name * @param town1 name of town 1 (lastname, firstname) * @param town2 name of town 2 (lastname, firstname) * @param roadName name of road * @return true if the road was added successfully */ public boolean addRoad(String town1, String town2, String roadName); /** * Returns the name of the road that both towns are connected through * @param town1 name of town 1 (lastname, firstname) * @param town2 name of town 2 (lastname, firstname) * @return name of road if town 1 and town2 are in the same road, returns null if not */ public String getRoad(String town1, String town2); /** * Adds a town to the graph * @param v the town's name (lastname, firstname) * @return true if the town was successfully added, false if not */ public boolean addTown(String v); /** * Determines if a town is already in the graph * @param v the town's name (lastname, firstname) * @return true if the town is in the graph, false if not */ public boolean containsTown(String v); /** * Determines if a road is in the graph * @param town1 name of town 1 (lastname, firstname) * @param town2 name of town 2 (lastname, firstname) * @return true if the road is in the graph, false if not */ public boolean containsRoadConnection(String town1, String town2); /** * Creates an arraylist of all road titles in sorted order * @return an arraylist of all road titles in sorted order */ public ArrayListallRoads(); /** * Deletes a road from the graph * @param town1 name of town 1 (lastname, firstname) * @param town2 name of town 2 (lastname, firstname) * @param roadName the road name * @return true if the road was successfully deleted, false if not */ public boolean deleteRoadConnection(String town1, String town2, String road); /** * Deletes a town from the graph * @param v name of town (lastname, firstname) * @return true if the town was successfully deleted, false if not */ public boolean deleteTown(String v); /** * Creates an arraylist of all towns in alphabetical order (last name, first name) * @return an arraylist of all towns in alphabetical order (last name, first name) */ public ArrayList allTowns(); /** * Returns the shortest path from town 1 to town 2 * @param town1 name of town 1 (lastname, firstname) * @param town2 name of town 2 (lastname, firstname) * @return an Arraylist of roads connecting the two towns together, null if the * towns have no path to connect them. */ public ArrayList getPath(String town1, String town2); }
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