i have the codes for Edge,graph,Node,deliA
import java.io.*;
import java.util.*;
// Class DelivA does the work for deliverable DelivA of the Prog340
public class DelivA {
File inputFile;
File outputFile;
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%n", x);
System.exit(0);
}
System.out.println( "DelivA: To be implemented");
output.println( "DelivA: To be implemented");
output.flush();
}
}
ICS 340 Programming Project, Deliverable A 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. Output: Here is sample output for one graph. val AAA Alfa Bravo 62 999 -42 3 Charlie 4 Delta 3 22 Echo yes DDD 99 E fig X 9 1-2 33 de The output for this file should be: Edge from Alpha to Bravo labeled > Kdge from Alpha to Delta labeled 99. Edge from Alpha to Echo labeled fig. Edge from Bravo to xlpha labeled 999. Kdge from bravo to Bravo labeled - 42. Edge from bravo to Charlie labeled 3. Edge from BRAVO to Delta Labeled x. Edge from Bravo to koho labelud - Edge from Charlie to havo labeled 4. Edge from Charlie to Delta labeled y. Kage from Charlie to Echo labeled 9. a University Windows computer systems. E Output: Here is sample output for one graph. val AAA BB Alfa X > Bravo 67 999 -42 3 Charlie 4 Delta 4e 3 22 X Echo yes fig DDD 99 x yz 9 1-2 33 de 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 be. Edge from Echo to Echo labeled 33. The order in which the Edges print out is not important. See the 40 spring 2020.docx file for details a Programming Project There will be one multi-deliverable Java programming project this semester, which will be divided into three separately-graded program deliverables (DelivA through Delive). A specification for each deliverable will be uploaded to D2L. Each deliverable will build on past deliverables. Start from a Working Program Some Java programs work on student computers but not on University lab (Windows) computers or grading computer. So this semester, you are given an initial codebase, Prog340", that seems to compile and run on all platforms. It opens a menu for you to select an action. It has a number of predefined menu items describing the various actions (which you will implement during the semester). o When you start the program the first action you will want to take will be to read a file. The input files for all deliverables have the same, specified format. It allows you to continuously select actions as long as you wish o Including read another file. It allows you to exit the program. Each Deliverable will involve your modifying your existing program (DelivA involves modifying the initial program given to you). This minimizes any duplicate effort. But it means that if you screw up a deliverable, you may have screwed up another deliverable later in the course. . Grading Deliverable A is worth 25 points. It is pretty simple if you understand o programming in Java. For each of Deliverables B (50 pts) and C (55 pts): Correct functioning of the program is worth 40 and points (DelivB and DelivC). You will receive a set of test files which will be used to evaluate the program. Some other test files may also be used that are not given to you (in real life, you design to the specification, you can't test everything). You will receive the desired output for at least one test file. Part of learning the material in the class is figuring out the correct answer to the test files yourself. The correctness points are divided among the tests. For instance, if there are 8 tests, each test is worth 10 points. Normally, a test is either all or nothing. Oor max points, but you can get substantial partial credit for output whose content is correct, but whose formatting is off For Deliverable C, there will be a report worth 5 points. Program Architecture The initial program reads a text file and interprets it as a graph. 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 I or more spaces (not tabs): I I ICS 340 Spring 2021 C val x 67 DDD E 99 fig 999 BB > -42 4 22 Alfa Bravo Charlie Delta Echo 3 ya 3 4e yes 9 !-2 de 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. o "val" is a column label for the column of node values The rest of the strings are mnemonies for the nodes of the graph. They are alphanumerie and do not contain spaces Each subsequent row describes one node and its outgoing edges. The first column contains the name of the node (eg, "Alfa") The string in the "val" column is the value of the node, which may be numere, 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. (eg, there is no edge from node "Charlie" to node "Alfa") O 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 su in the appropriate column. (e.g., there is no edge from node "Charlie" to node "Alfa") o 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. If you like a picture of what this is, here's what the above table locks like in graphical form: Eiche AM Alfa DOO De L Chwi Prog340 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 Graph File inputFile ArrayList
nodeList File outputFile ArrayList getNodelist) String[] comboBoxList ArrayList( comboBoxtist ); 99 actionList.setName("Action List"); 10e actionList.setSelectedIndex(); 18: actionList.addActionListener( this ); 102 add( actionList, BorderLayout.PAGE_START); 103 } 105 1/ Listen to the Combo Box 1868 public void actionPerformed( ActionEvent e) { 107 ComboBox cb - (ComboBox)e.getSource(); 1108 int action Index - cb.getSelectedIndex(); leg 110 switch( action Index ) { 113 case : B - new Graph(); readGraphInfo( 8 ); break; 115 116 117 118 119 120 121 case 1: DelivA dA new Deliv input file break; case 2: Writable Smart Insert 118:52144 HF Type here to search ORI * a case 2: DelivB dB = new DelivB( inputFile, 8 ); break; case 3: Delivc dc = new Delivc( inputFile, 8 ); break; 36 case 4: 9 System.out.println("Goodbye"); 1 System.exit(0); 12 33 default: 34 System.out.println("Invalid choice" ); 35 System.ekit(); } 37 338 m39e/* Read the file containing the Strings, line by line, then process each line as it is read. 140 **/ 1418 public void readGraphInfo( Graph 8 ) { 142 143 try { 144 145 if (fileChooser.showOpenDialog(null) 146 ** JFileChooser APPROVE_OPTION) { 1/ Instantiate the selected input and output files. 148 inputFile = fileChooser.getSelectedFile(); System.out.println("Chosen file - " + inputFile + " "); 3 151 71 read text file Scanner se - new Scanner( inputFile ); 1/ First line special: It contains "w", and "vol", and the nodes with the edges. 155 String firstline - sc.nextLine(); String[] splitstring - firstline.split(" +"); 157 158 // Ignore first two fields of first line, Every other field is a node Enrint - enl+string laneth 147 149 150 152 153 154 156 1 53 read text file Scanner sc = new Scanner( inputFile ); Il First line special: It contains "w", and "val", and the nodes with the edges. String firstline = sc.nextLine(); String[] splitString = firstline.split("+" ); 55 56 158 159 168 1/ Ignore first two fields of first line, Every other field is a node. for (int i = 2; 1 nodelist - 8-getNodelist(); while (sc. has extLine()) { String nextLine - sc.nextLine(); splitString - nextLine.split(" "); Nodennodelist.get( nodeIndex); n.settime( splittring[@] ); . setvall splitString[i] ); for (int i = 2; 1 node Index 176 172 179 150 101 199 11 18s Sac 107 18 19 190 s.close(); Type here to search O i 118.52 3 a 162 } 17 Every other line gives the name and value of the Node, and any edges. int nodeIndex = 0; ArrayList nodelist = 8.getNodeList(); 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 183 189 190 191 192 while ( sc. hasNextLine()) { String nextLine - sc.nextLine(); splitString = nextLine.split(" +"); Node na nodeList.get( nodeIndex ); in.setName( splitString[0] ); n.setVal splitstring[1] ); for (int i = 2; i Kdge from Alpha to Delta labeled 99. Edge from Alpha to Echo labeled fig. Edge from Bravo to xlpha labeled 999. Kdge from bravo to Bravo labeled - 42. Edge from bravo to Charlie labeled 3. Edge from BRAVO to Delta Labeled x. Edge from Bravo to koho labelud - Edge from Charlie to havo labeled 4. Edge from Charlie to Delta labeled y. Kage from Charlie to Echo labeled 9. a University Windows computer systems. E Output: Here is sample output for one graph. val AAA BB Alfa X > Bravo 67 999 -42 3 Charlie 4 Delta 4e 3 22 X Echo yes fig DDD 99 x yz 9 1-2 33 de 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 be. Edge from Echo to Echo labeled 33. The order in which the Edges print out is not important. See the 40 spring 2020.docx file for details a Programming Project There will be one multi-deliverable Java programming project this semester, which will be divided into three separately-graded program deliverables (DelivA through Delive). A specification for each deliverable will be uploaded to D2L. Each deliverable will build on past deliverables. Start from a Working Program Some Java programs work on student computers but not on University lab (Windows) computers or grading computer. So this semester, you are given an initial codebase, Prog340", that seems to compile and run on all platforms. It opens a menu for you to select an action. It has a number of predefined menu items describing the various actions (which you will implement during the semester). o When you start the program the first action you will want to take will be to read a file. The input files for all deliverables have the same, specified format. It allows you to continuously select actions as long as you wish o Including read another file. It allows you to exit the program. Each Deliverable will involve your modifying your existing program (DelivA involves modifying the initial program given to you). This minimizes any duplicate effort. But it means that if you screw up a deliverable, you may have screwed up another deliverable later in the course. . Grading Deliverable A is worth 25 points. It is pretty simple if you understand o programming in Java. For each of Deliverables B (50 pts) and C (55 pts): Correct functioning of the program is worth 40 and points (DelivB and DelivC). You will receive a set of test files which will be used to evaluate the program. Some other test files may also be used that are not given to you (in real life, you design to the specification, you can't test everything). You will receive the desired output for at least one test file. Part of learning the material in the class is figuring out the correct answer to the test files yourself. The correctness points are divided among the tests. For instance, if there are 8 tests, each test is worth 10 points. Normally, a test is either all or nothing. Oor max points, but you can get substantial partial credit for output whose content is correct, but whose formatting is off For Deliverable C, there will be a report worth 5 points. Program Architecture The initial program reads a text file and interprets it as a graph. 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 I or more spaces (not tabs): I I ICS 340 Spring 2021 C val x 67 DDD E 99 fig 999 BB > -42 4 22 Alfa Bravo Charlie Delta Echo 3 ya 3 4e yes 9 !-2 de 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. o "val" is a column label for the column of node values The rest of the strings are mnemonies for the nodes of the graph. They are alphanumerie and do not contain spaces Each subsequent row describes one node and its outgoing edges. The first column contains the name of the node (eg, "Alfa") The string in the "val" column is the value of the node, which may be numere, 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. (eg, there is no edge from node "Charlie" to node "Alfa") O 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 su in the appropriate column. (e.g., there is no edge from node "Charlie" to node "Alfa") o 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. If you like a picture of what this is, here's what the above table locks like in graphical form: Eiche AM Alfa DOO De L Chwi Prog340 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 Graph File inputFile ArrayList nodeList File outputFile ArrayList getNodelist) String[] comboBoxList ArrayList( comboBoxtist ); 99 actionList.setName("Action List"); 10e actionList.setSelectedIndex(); 18: actionList.addActionListener( this ); 102 add( actionList, BorderLayout.PAGE_START); 103 } 105 1/ Listen to the Combo Box 1868 public void actionPerformed( ActionEvent e) { 107 ComboBox cb - (ComboBox)e.getSource(); 1108 int action Index - cb.getSelectedIndex(); leg 110 switch( action Index ) { 113 case : B - new Graph(); readGraphInfo( 8 ); break; 115 116 117 118 119 120 121 case 1: DelivA dA new Deliv input file break; case 2: Writable Smart Insert 118:52144 HF Type here to search ORI * a case 2: DelivB dB = new DelivB( inputFile, 8 ); break; case 3: Delivc dc = new Delivc( inputFile, 8 ); break; 36 case 4: 9 System.out.println("Goodbye"); 1 System.exit(0); 12 33 default: 34 System.out.println("Invalid choice" ); 35 System.ekit(); } 37 338 m39e/* Read the file containing the Strings, line by line, then process each line as it is read. 140 **/ 1418 public void readGraphInfo( Graph 8 ) { 142 143 try { 144 145 if (fileChooser.showOpenDialog(null) 146 ** JFileChooser APPROVE_OPTION) { 1/ Instantiate the selected input and output files. 148 inputFile = fileChooser.getSelectedFile(); System.out.println("Chosen file - " + inputFile + " "); 3 151 71 read text file Scanner se - new Scanner( inputFile ); 1/ First line special: It contains "w", and "vol", and the nodes with the edges. 155 String firstline - sc.nextLine(); String[] splitstring - firstline.split(" +"); 157 158 // Ignore first two fields of first line, Every other field is a node Enrint - enl+string laneth 147 149 150 152 153 154 156 1 53 read text file Scanner sc = new Scanner( inputFile ); Il First line special: It contains "w", and "val", and the nodes with the edges. String firstline = sc.nextLine(); String[] splitString = firstline.split("+" ); 55 56 158 159 168 1/ Ignore first two fields of first line, Every other field is a node. for (int i = 2; 1 nodelist - 8-getNodelist(); while (sc. has extLine()) { String nextLine - sc.nextLine(); splitString - nextLine.split(" "); Nodennodelist.get( nodeIndex); n.settime( splittring[@] ); . setvall splitString[i] ); for (int i = 2; 1 node Index 176 172 179 150 101 199 11 18s Sac 107 18 19 190 s.close(); Type here to search O i 118.52 3 a 162 } 17 Every other line gives the name and value of the Node, and any edges. int nodeIndex = 0; ArrayList nodelist = 8.getNodeList(); 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 183 189 190 191 192 while ( sc. hasNextLine()) { String nextLine - sc.nextLine(); splitString = nextLine.split(" +"); Node na nodeList.get( nodeIndex ); in.setName( splitString[0] ); n.setVal splitstring[1] ); for (int i = 2; i