Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Java program Graph.java with a public class Graph which allows creating a graph that is then output as a LaTeX file as described

Create a Java program Graph.java with a public class Graph which allows creating a graph that is then output as a LaTeX file as described above. It should have the following public methods:

addNode

addEdge

clear outheader outfooter 

outgraph

outgrid main

Add a node to the graph, given by a pair of integer coordinates, together with a label string (such as 1000 in the example above). If the same coordinate pair is given again, update the label (so do not store the same node twice). The coordi- nates can be positive or negative but should in absolute value not be larger than an integer constant maxcoordinate , which you should set to 100 at a central place. Reject nodes where a coordinate exceeds this value with a LaTeX comment (on its own output line) as in % coordinate 190 in node (50,190) too large

Add a directed edge to the graph, given by the two pairs of integer coordinates of the endpoints of the edge. These nodes have to be present already; if not, reject them with a suitable LaTeX comment.

Empty the node and edge list. Output the header of the LaTeX file, i.e., the preamble up to \begin{document}

Output the footer of the LaTeX file, here the single line \end{document} . You could prefix it with \medskip\hrule if you like the resulting output better.

Output the graph as a tikz figure as described, with a blank line before and after, and including a green grid at the beginning. (There may be several such figures in a single LaTeX file, hence the separate outheader and outfooter methods.)

Output a grid between the smallest and largest coordinates that occur, in turn computed by a separate method.

This standard static method will only be used to test the Graph methods. Invoked with java Graph x1 y1 x2 y2 xn yn , it should create a path with edges (x1, y1) (x2, y2), . . . , (xn1, yn1) (xn, yn) from the sequence of pairs of co- ordinates given on the command line. The labels of the nodes are the numbers 1, . . . , n (possibly overwritten when a node is used twice)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is Balance Sheet Management

Answered: 1 week ago