The purpose of this project is to assess your ability to (JAVA): Implement a graph abstract data type. The getDistance method should print the distance of all connected nodes/ vertices.   A graph is a set of vertices and a set of edges. Represent the vertices in your graph with an array of strings:   Represent the edges in your graph as a two-dimensional array of integers. Use the distances shown in the graph pictured here. Add the following functions to your graph class: A getDistance function that takes two vertices and returns the length of the edge between them. If the vertices are not connected, the function should return the max value for an integer. A getNeighbors function that takes a single vertex and returns a list of all the vertices connected to that vertex. A print method that outputs an adjacency matrix for your graph. Write a test program for your Graph class.

icon
Related questions
Question

The purpose of this project is to assess your ability to (JAVA):

  • Implement a graph abstract data type.
  • The getDistance method should print the distance of all connected nodes/ vertices.

 

A graph is a set of vertices and a set of edges. Represent the vertices in your graph with an array of strings:

 

Represent the edges in your graph as a two-dimensional array of integers. Use the distances shown in the graph pictured here.

Add the following functions to your graph class:

  • A getDistance function that takes two vertices and returns the length of the edge between them. If the vertices are not connected, the function should return the max value for an integer.
  • A getNeighbors function that takes a single vertex and returns a list of all the vertices connected to that vertex.
  • A print method that outputs an adjacency matrix for your graph.

Write a test program for your Graph class. 

Mohave
12
La Paz
11
Yavapai
14
Maricopa
Coconino
13
Yuma
2
Navajo
10
Gila
8
Pinal
7
Pima
9
Graham
Apache
6
Santa
Cruz
Cochise
4
Greenlee
16
strings:
vertices[0]
vertices [1]
vertices[2] Navajo
vertices[3] Apache
vertices[4] Greenlee
vertices[5] Cochise
vertices[6] Santa Cruz
vertices[7] Pima
vertices[8] Pinal
vertices[9] Graham
Gila
Mohave
Coconino
vertices [10]
vertices[11]
Yavapai
La Paz
vertices[12]
vertices [13]
Yuma
vertices[14] Maricopa
Transcribed Image Text:Mohave 12 La Paz 11 Yavapai 14 Maricopa Coconino 13 Yuma 2 Navajo 10 Gila 8 Pinal 7 Pima 9 Graham Apache 6 Santa Cruz Cochise 4 Greenlee 16 strings: vertices[0] vertices [1] vertices[2] Navajo vertices[3] Apache vertices[4] Greenlee vertices[5] Cochise vertices[6] Santa Cruz vertices[7] Pima vertices[8] Pinal vertices[9] Graham Gila Mohave Coconino vertices [10] vertices[11] Yavapai La Paz vertices[12] vertices [13] Yuma vertices[14] Maricopa
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer