Supplemental Graph Class Instructions
The Graph class Graph.java as given to you, has a constructor that takes the input file
name, and the following methods:
- loadGraphFile(..) // loads the matrix
- addEdge(..) // adds weight at src, dest
- toString()
Enhancements you are to make to above class definition
- Add try catch only to the removeEdge method
- In your catch block just print out the Exception you caught and then call System.exit(0);
Methods you are to add to the Graph class
Add the following private new methods to the Graph class.
- private boolean hasEdge( int src, int dest ) // T/F edge here ?
- private int inDegree( int node )
// in degree of single node
- private int outDegree( int node )
// out degree of single node
- private int degree( int node )
// degree of a single node (= in+out)
Then to add the following public new methods to the Graph class.
- public int maxInDegree()
- public int maxOutDegree()
- public int maxDegree()
- public int minInDegree()
- public int minOutDegree()
- public int minDegree()
A word about efficiency and OOP: I will be deducting points
(small penalty) if you are grossly inefficient in how you write your methods.
I will also deduct (a bit more of a penalty for this ) if you write code to
do something that could have been done using the member functions already given
to you. Think about every calculation you do and ask: "Is there
something already written for me that will do this?" Being able to recognize and
use existing code to do a task is a fundamental skill. I will continue to place a premium on in.
Don't store results of previous computations in
arrays or data structures - just call the private single node degree methods in a loop to compute your
public mins and maxes etc.
Write yor private hasEdge() inDegree() outDegree() and degree() methods first and test them first, before writing the
public methods minDegrees and maxDegrees etc.