1. Engineering
  2. Computer Science
  3. write code necessary to print out for each edge the...

Question: write code necessary to print out for each edge the...

Question details
  1. Write code necessary to print out, for each Edge, the name of the Node from which the Edge emanates, the name of the Node at which the Edge terminates, and the label of the Edge, in the format listed below.

Submit the Java source code to the open Deliverable A submission folder. You may submit either the source code or a full Eclipse package.

Output:

Here is sample output for one graph.

~          val AAA   BB    C DDD    E

Alfa         x    ~    >    ~   99 fig

Bravo       67 999 -42    3    x   ==

Charlie      ~    ~    4    ~   yz    9

Delta       4e    3   22    x    ~ !=2

Echo       yes    ~    ~    ~ d>e   33

The output for this file should be:

Edge from Alpha to Bravo labeled >.

Edge from Alpha to Delta labeled 99.

Edge from Alpha to Echo labeled fig.

Edge from Bravo to Alpha labeled 999.

Edge from Bravo to Bravo labeled -42.

Edge from Bravo to Charlie labeled 3.

Edge from Bravo to Delta labeled x.

Edge from Bravo to Echo labeled ==.

Edge from Charlie to Bravo labeled 4.

Edge from Charlie to Delta labeled yz.

Edge from Charlie to Echo labeled 9.

Edge from Delta to Alpha labeled 3.

Edge from Delta to Bravo labeled 22.

Edge from Delta to Charlie labeled x.

Edge from Delta to Echo labeled !=2.

Edge from Echo to Delta labeled d>e.

Edge from Echo to Echo labeled 33.

The order in which the Edges print out is not important.

Input File

All the input files in this course will look something like this, file A0.txt. Note that all columns of data are separated by 1 or more spaces (not tabs):

~          val AAA   BB    C DDD    E

Alfa         x    ~   >    ~   99 fig

Bravo       67 999 -42    3    x   ==

Charlie      ~    ~    4    ~   yz    9

Delta       4e    3   22    x    ~ !=2

Echo       yes    ~    ~    ~ d>e   33

  • The first row is a header row.
  • The first “~” is merely a placeholder. All files will have this at the beginning of the header row.
  • “val” is a column label for the column of node values.
  • The rest of the strings are mnemonics for the nodes of the graph. They are alphanumeric and do not contain spaces.
  • Each subsequent row describes one node and its outgoing edges.
  • The first column contains the name of the node (e.g., “Alfa”)
  • The string in the “val” column is the value of the node, which may be numeric, but which will certainly always consist of a string of printable characters. The character “~“ by itself stands for “no value”. (e.g., node “Charlie” has no value.)
  • For the rest of the columns, if there is no edge going from the node to another node, there is a “~“ in the appropriate column. (e.g., there is no edge from node “Charlie” to node “Alfa”.)
  • If there is anything else in that column, that is the label of the edge. For some deliverables, this will be numeric, for others it may not be. Note that self edges are allowed. (e.g., the edge from “Delta” to “Echo” has label “!=2”.)

Test Files:

The program correctness will be tested with various test files. Some test files are specific to a given deliverable, others may be used to test multiple deliverables. The test file naming convention is: XXXnnn.txt. XXX denotes the set of deliverables that this file pertains to, nnn is a unique number for the file. For instance, file A0.txt is a test file for deliverable A, while file ABD2.txt is a test file for deliverables A, B, and D.

Note that a file may be modified for a given deliverable. For instance, consider file ABD6.txt:

~          val Atl Bos Chi Dal Den   LA Mia Min   NY   SF Sea Was

Atlanta      ~    0 957 581 725 1220 1942 608 898 752 2155 2201 538

Boston       G 957    0 859 1571 1783 2594 1285 1127 207 2719 2505 420

Chicago      ~ 581 859    0 803 928 1736 1185 354 718 1876 1758 601

Dallas       ~ 725 1571 803    0 667 1248 1116 851 1384 1494 1698 1190

Denver       ~ 1220 1783 928 667    0 812 1736 697 1645 957 1033 1507

LosAngeles   S 1942 2594 1736 1248 812    0 2357 1500 2451 313 923 2301

Miami        ~ 608 1285 1185 1116 1736 2357    0 1505 1097 2611 2755 917

Minneapolis ~ 898 1127 354 851 697 1500 1505    0 1024 1597 1415 940

NewYork      ~ 752 207 718 1384 1645 2451 1097 1024    0 2594 2430 213

SanFrancisco ~ 2155 2719 1876 1494 957 313 2611 1597 2594    0 691 2464

Seattle      ~ 2201 2505 1758 1698 1033 923 2755 1415 2430 691    0 2354

Washington   ~ 538 420 601 1190 1507 2301 917 940 213 2464 2354    0

This file lists distances between cities. For deliverables B and D you will want to start from a given city (with value “S”) and search for a given city (value “G”). For testing purposes, we may use different starting and finishing cities (and you should do so, too, while testing your program).

Graph is a class whose objects represent graphs.

Node is a class whose objects represent nodes (a.k.a., vertices) in the graph.

Edge is a class whose objects represent edges (a.k.a., arcs) between nodes of the graph. Note that each edge has a direction. It goes from one specific node to another specific node.

Here is a basic UML class diagram for these four classes. All methods and attributes are listed explicitly rather than using composition connectors, to be easily understood by people with little UML background.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution