Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need as java program DelivA Code given: Specification: Start with the given Java program prog340, which lets you select a file to read from your

Need as java program

image text in transcribed

image text in transcribed

image text in transcribed

DelivA Code given:

image text in transcribed

Specification: Start with the given Java program prog340, which lets you select a file to read from your computer, reads the file, and interprets that file as the specification of a graph.' Then enhance it to do the following: 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. The prog340 handout describes the format of the input file for this and all program deliverables. As will always be the case in this class, the program must be written in Java and must run on the University Windows computer systems. BE Output: Here is sample output for one graph. val AAA Alfa Bravo 67 999 -42 Charlie 4 Delta 4e 3 22 Echo yes DDD 99 E fig 3 yz x 9 !=2 33 d>e 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 de. Edge from Echo to Echo labeled 33. The order in which the Edges print out is not important. Program Classes and Methods There are 4 classes in the program given to you in addition to a sub class for each deliverable, A-C): Prog 340 is the main class, which handles the I/O. 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. Prog340 File inputFile File outputFile Print Writer output JFileChooser fileChooser Graph g String[] combo BoxList Graph ArrayList nodeList ArrayList edgelist Graph() ArrayList getNodeList() ArrayList get EdgeList() void add Node( Node) void add Edge Edge ) String toString() Prog3400) void main() void createAndShowGUI() void action Performed Actino Event) void read Graph Info() Node ArrayList outgoing Edges ArrayList incomingEdges String name String val String abbrev Edge String label Node tail Node head Edge( Node, Node, String) String getLabell) Node getTaill) Node getHead() void set Label( String) void set Tail( Node) void set Head( Node) Node( String) String getName() String getVal) String getAbbreve) ArrayList get Outgoing Edges() ArrayList get Incoming Edges() void setAbbrev( String) void setNamel String) void set Val( String) void add OutgoingEdge Edge) void add IncomingEdge Edge ) Input File All the input files in this course will look something like this, file AB0.txt. Note that all columns of data are separated by 1 or more spaces (not tabs): ICS 340 Spring 2021 val AAA BB E fig 67 999 Alfa Bravo Charlie Delta Echo 3 DDD 99 x yz -42 4 22 9 !=2 3 X 4e yes d>e 33 The first row is a header row. o o o o 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.) o 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. 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. o o If you like a picture of what this is, here's what the above table looks like in graphical form: 33 Echo yes AAA Alfa 99 3 DDO Delta 22 BB Bravo 67 -42 c Charlie DelivA.java import java.io.*; import java.util.*; 1/ Class DelivA does the work for deliverable DelivA of the Prog340 public class DelivA { File inputFile; File output File; Printwriter output; Graph g; public DelivA( File in, Graph gr ) { inputFile = in; g = gr; // Get output file name. String inputFileName = inputFile.toString(); String baseFileName = inputFileName.substring( 0, inputFileName. length()-4); // Strip off ".txt" String outputFileName = baseFileName.concat("_out.txt" ); outputFile = new File( outputFileName); if (outputFile.exists()) { // For retests outputFile.delete(); } try { output = new PrintWriter(outputFile); } catch (Exception x ) { System.err.format("Exception: %s%", x); System.exit(0); } System.out.println("DelivA: To be implemented"); output.println("DelivA: To be implemented"); output. flush(); } } Specification: Start with the given Java program prog340, which lets you select a file to read from your computer, reads the file, and interprets that file as the specification of a graph.' Then enhance it to do the following: 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. The prog340 handout describes the format of the input file for this and all program deliverables. As will always be the case in this class, the program must be written in Java and must run on the University Windows computer systems. BE Output: Here is sample output for one graph. val AAA Alfa Bravo 67 999 -42 Charlie 4 Delta 4e 3 22 Echo yes DDD 99 E fig 3 yz x 9 !=2 33 d>e 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 de. Edge from Echo to Echo labeled 33. The order in which the Edges print out is not important. Program Classes and Methods There are 4 classes in the program given to you in addition to a sub class for each deliverable, A-C): Prog 340 is the main class, which handles the I/O. 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. Prog340 File inputFile File outputFile Print Writer output JFileChooser fileChooser Graph g String[] combo BoxList Graph ArrayList nodeList ArrayList edgelist Graph() ArrayList getNodeList() ArrayList get EdgeList() void add Node( Node) void add Edge Edge ) String toString() Prog3400) void main() void createAndShowGUI() void action Performed Actino Event) void read Graph Info() Node ArrayList outgoing Edges ArrayList incomingEdges String name String val String abbrev Edge String label Node tail Node head Edge( Node, Node, String) String getLabell) Node getTaill) Node getHead() void set Label( String) void set Tail( Node) void set Head( Node) Node( String) String getName() String getVal) String getAbbreve) ArrayList get Outgoing Edges() ArrayList get Incoming Edges() void setAbbrev( String) void setNamel String) void set Val( String) void add OutgoingEdge Edge) void add IncomingEdge Edge ) Input File All the input files in this course will look something like this, file AB0.txt. Note that all columns of data are separated by 1 or more spaces (not tabs): ICS 340 Spring 2021 val AAA BB E fig 67 999 Alfa Bravo Charlie Delta Echo 3 DDD 99 x yz -42 4 22 9 !=2 3 X 4e yes d>e 33 The first row is a header row. o o o o 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.) o 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. 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. o o If you like a picture of what this is, here's what the above table looks like in graphical form: 33 Echo yes AAA Alfa 99 3 DDO Delta 22 BB Bravo 67 -42 c Charlie DelivA.java import java.io.*; import java.util.*; 1/ Class DelivA does the work for deliverable DelivA of the Prog340 public class DelivA { File inputFile; File output File; Printwriter output; Graph g; public DelivA( File in, Graph gr ) { inputFile = in; g = gr; // Get output file name. String inputFileName = inputFile.toString(); String baseFileName = inputFileName.substring( 0, inputFileName. length()-4); // Strip off ".txt" String outputFileName = baseFileName.concat("_out.txt" ); outputFile = new File( outputFileName); if (outputFile.exists()) { // For retests outputFile.delete(); } try { output = new PrintWriter(outputFile); } catch (Exception x ) { System.err.format("Exception: %s%", x); System.exit(0); } System.out.println("DelivA: To be implemented"); output.println("DelivA: To be implemented"); output. flush(); } }

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

Recommended Textbook for

Data Science For Dummies

Authors: Lillian Pierson ,Jake Porway

2nd Edition

1119327636, 978-1119327639

More Books

Students also viewed these Databases questions