Produce a program similar to a GPS system. The code will read in a pre-defined file with all the information you will need to calculate
Produce a program similar to a GPS system. The code will read in a pre-defined file with all the information you will need to calculate the least costly path from one point to another on the graph. The user will have the ability to choose if they want one cost over another (distance cost or time cost), as well as ask for the location symbol (A - T) or the street address associated with the symbol.
1. Use your own Generic heap PriorityQueue to be used with your Dijkstra' s Shortest algorithm.
2. Read in a set of data from a text file which will contain vertices with both a symbol and an address to represent locations on a map. The file will also contain a set of connections between vertices with both a distance and time cost between them.
3. Produce a user interface (GUI) Users should be able to select a from and a to address and be give the least costly path based on user selection (see below)
4. Produce at least the following classes: a. Vertex b. Edge c. Path
d. Graph that contains the following: i. Two public static booleans called: 1. useDistCost 2. returnAddress
ii. A constructor that accepts a filename as a string.
iii. The toString() method that returns all vertices and costs (both dependent on the two static Booleans above
e. Dijkstra that contains the following:
i. A static method called shortestPath that returns a Path ii. A static int called totalCost f. Tester class for testing The format of the map file is as follows with tabs separating fields: Symbol Address A 1121 N Bend Rd. B 1521 Grassland Ave. ... Source Destination TimeCost DistanceCost A C 4 8 A Q 3 6 A T 5 10 ...
Important references:
MapInformation.txt
Symbol Address A 1121 N Bend Rd. B 1521 Grassland Ave. C 22 Main St. D 44 W Lexington Ave. E 4423 Walnut St. F 1616 Levington Blvd. G 2402 N Bend Rd. H 33 Holden Ave. I 3411 Walnut St. J 44 Kirkland Dr. K 14 Pepper Ave. L 3311 N Bend Rd. M 15 Goodman Dr. N 510 Lake St. O 1600 N Bend Rd. P 55 Main St. Q 5500 Walnut St. R 11 Savannah Dr. S 20 Hopper Blvd. T 9810 Miami Blvd. Source Destination TimeCost DistanceCost A C 4 8 A Q 3 6 A T 5 10 B G 6 12 B H 8 16 B Q 2 16 B R 5 10 C D 2 4 C J 8 16 C L 8 16 D F 4 8 D N 7 14 D T 1 4 E G 8 5 E I 7 14 E O 4 8 E Q 3 6 F M 10 20 F R 6 16 G D 1 60 H K 6 12 H L 2 5 I E 5 14 J C 7 16 K H 4 12 L C 2 16 L H 1 5 M F 6 20 N S 4 8 O E 7 8 O P 4 8 P C 4 8 P F 8 4 P O 3 8 P T 7 14 Q B 8 16 R F 8 16 S D 3 6 S T 6 9 T D 2 4 T S 4 9
MapInformationXY
Symbol Address x y A 1121 N Bend Rd. 263 147 B 1521 Grassland Ave. 110 129 C 22 Main St. 155 213 D 44 W Lexington Ave. 244 273 E 4423 Walnut St. 275 69 F 1616 Levington Blvd. 165 291 G 2402 N Bend Rd. 196 153 H 33 Holden Ave. 27 80 I 3411 Walnut St. 369 65 J 44 Kirkland Dr. 81 308 K 14 Pepper Ave. 110 32 L 3311 N Bend Rd. 37 175 M 15 Goodman Dr. 136 384 N 510 Lake St. 229 366 O 1600 N Bend Rd. 341 151 P 55 Main St. 247 213 Q 5500 Walnut St. 188 70 R 11 Savannah Dr. 82 231 S 20 Hopper Blvd. 320 329 T 9810 Miami Blvd. 335 235 /********************************************************* These are comments... /********************************************************* Source Destination TimeCost DistanceCost A C 4 8 A Q 3 6 A T 5 10 B G 6 12 B H 8 16 B Q 2 16 B R 5 10 C D 2 4 C J 8 16 C L 8 16 D F 4 8 D N 7 14 D T 1 4 E G 8 5 E I 7 14 E O 4 8 E Q 3 6 F M 10 20 F R 6 16 G D 1 60 H K 6 12 H L 2 5 I E 5 14 J C 7 16 K H 4 12 L C 2 16 L H 1 5 M F 6 20 N S 4 8 O E 7 8 O P 4 8 P C 4 8 P F 8 4 P O 3 8 P T 7 14 Q B 8 16 R F 8 16 S D 3 6 S T 6 9 T D 2 4 T S 4 9
readFile
public void readFile(String fileName) { try { // Creates a scanner Scanner file = new Scanner(new File(fileName)); String line = file.nextLine(); // Skips lines until the Nodes are reached while (!line.equals("")) { line = file.nextLine(); } // Skips two lines of header text in the file file.nextLine(); line = file.nextLine(); // Creates Vertex objects (each of which contains a symbol and an address property) while (!line.equals(" ")) { String[] s = line.split("\t"); line = file.nextLine(); } // Skips lines until Edges are reached while (!line.equals("")) { line = file.nextLine(); } file.nextLine(); // Creates Edge objects (each of which contains a source, destination, time cost, // and distance cost property) and adds them to a set line = file.nextLine(); String[] s = line.split("\t"); while (!line.equals(" ")) { do { line = file.nextLine(); s = line.split("\t"); } while (s[0].equals(v.getSymbol())); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (Exception f) { f.printStackTrace(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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