1
Student Name: __________________
Class and Section __________________
Total Points (20 pts) __________________
Due: Wednesday Oct 13, 2010 before the class
Project: Display a Graph
CSCI 1302 Advanced Programming Principles
Armstrong Atlantic State University
Problem Description:
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 u x y v1, v2, …, describes that the
vertex u is located at position (x, y) with edges (u, v1), (u, v2),
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).
File
6
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
0
2
3
1
5
(a) (b)
The program reads the information about the graph and
displays it visually.
Analysis:
A graph is a mathematical structure with vertices and
Design:
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
2
information into a twodimensional array named
position, where (position[0][0], position[0][1]) is
the xand ycoordinates for vertex 0. For example,
in the sample graph, (position[0][0],
int[][] position = new int[n][2];
ArrayList[] edge = new ArrayList[n];
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.
Draw the UML diagram for GraphView and Exercise14_09Extra:
Coding:
Name your main class Exercise14_09Extra. You code will
look like this:
Two Testing:
1. use the sample graph given the Description of the
problem.
2. use the following graph file to test your program:
3
7
0 50 45 1 3 4
1 150 25 0 2 3 5
2 250 155 1 4 6
Screen shots:
Include the screen shots for the two tests here:
Must fill in self-evaluation:
1. Can your program read the data from the file into position and edge? ________
2. Did you draw the UML diagrams for Exercise14_27 and GraphView? _________
3. Can you define the GraphView class? _____________
4. Can your program display the graph correctly? ____________
Submit the following items:
1. Bring a printed copy of this file to the class.