Question: The program should first read the information about the graph from a file. The program prompts the user to enter the file name and read

 The program should first read the information about the graph from

The program should first read the information about the graph from a file. The program prompts the user to enter the file name and read vertices location information into a two-dimensional array named position, where (position[0][0], position[0][1]) is the x- and ycoordinates for vertex 0. For example, in the sample graph, (position[0][0], position[0][1]) is (30, 30). The program reads the edge information into an array of ArrayList named edge (ArrayList is covered in Chapter 11). For example, in the sample graph, edge[0] Is an ArrayList that contains elements 1 and 2, which indicates that vertex 0 is connected to vertex 1 and vertex 2. position and edge should be created as followed: int[][] position = new int[n][2]; ArrayList[] edge = new ArrayList[n]; CS265 Closed Lab 8 2 After the graph information are read into position and edge, we can use these information to display the graph. Define a class named GraphView that extends Pane, as follows: 1. data fields position and edge. 2. a constructor that constructs a GraphView object with the specified position and edge.

A graph consists of vertices and edges that connect vertices. Write a program that reads a graph from a file and displays it on a panel. The first line in the file contains a number that indicates the number of vertices (n). The vertices are labeled as 0, 1, .., n-1. Each subsequent line, with the format v1, v2 , , describes that the vertex u is located at position (x, y) with edges (u, vl),(, y2), etc. Figure (a) gives an example of the file for a graph. Your program prompts the user to enter the name of the file, reads data from the file, and displays the graph on a panel, as shown in Figure (b). Exercise14 09 File 0 30 30 1 2 1 90 30 0 3 2 30 90 0 3 4 3 90 90 1 2 4 5 4 30 150 2 3 5 5 90 150 3 4 The program reads the information about the graph and displays it visually

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!