The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 2 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
CMSC 350 Project 4The fourth programming project involves writing a program that behaves like the Java commandline compiler. Whenever we request that the Java compiler recompile a particular class, it notonly recompiles that class but every other class that depends upon it, directly or indirectly, and ina particular order. To make the determination about which classes need recompilation, the Javacompiler maintains a directed graph of class dependencies. Any relationship in a UML classdiagram of a Java program such as inheritance relationships, composition relationships andaggregations relationships indicate a class dependency. Â The main class for this project should create the GUI shown below: Â
The GUI must be generated by code that you write.Â
You may not use a drag-and-drop GUIgenerator.
Pressing the Build Directed Graph button should cause the specified input file that contains theclass dependency information to be read in and the directed graph represented by thosedependencies to be built.Â
The input file associated with the above example is shown below:
ClassA ClassC ClassE
ClassB ClassD ClassG
ClassE ClassB ClassF ClassH
ClassI ClassC
Each line of this file specifies classes that have other classes that depend upon them. The firstline, for example, indicates that ClassA has two classes that depend upon it, ClassC andClassE. In the context of recompilation, it means when ClassA is recompiled, ClassC andClassE must be recompiled as well. Using graph terminology, the first name on each line is thename of a vertex and the remaining are its associated adjacency list. Classes that have no dependent classes need not appear at the beginning of a separate line. Notice, for example, thatClassC is not the first name on any line of the file.
After pressing the Build Directed Graph button, one of following two messages should begenerated depending upon whether the specified file name could be opened:Once the graph has been built, the name of a class to be recompiled can be specified and theTopological Order button can be pressed. Provided a valid class name has been supplied, the listof classes that need to be recompiled should be listed in the order they are to be recompiled in the text area at the bottom of the window. An invalid class name should generate an appropriate error message.
The correct recompilation order is any topological order of the subgraph that emanates from thespecified vertex. Topological orders are not unique, but the one that is to be used for thisprogram is the one generated using a depth-first search of the graph. The algorithm for generating this topological order is shown below:
depth_first_search(vertex s)Â
if s is discoveredÂ
throw cycle detected exception
 if s is finishedÂ
returnÂ
mark s as discoveredÂ
for all adjacent vertices vÂ
depth_first_search(v)Â
mark s as finishedÂ
push s onto the stackÂ
This algorithm generates a reverse topological order so after it completes, the forward topological order can be ascertained by popping the vertices off the stack. Note that an exception is to be thrown if the graph contains a cycle. When circular dependencies exist in Java programs,the compiler must make two passes over all the classes in the cycle, first compiling the specifications and subsequently the remaining code. For this program, it will be sufficient to display a message indicating that a cycle has been detected.In addition to the main class that defines the GUI, a second class is needed to define the directed graph. It should be a generic class allowing for a generic type for the vertex names. In this application those names will be strings. The graph should be represented as an array list of vertices that contain a linked list of their associated adjacency lists. The adjacency lists should be lists of integers that represent the index rather than vertex name itself.
 A hash map should beused to associate vertex names with their index in the list of vertices:
For the input file shown above the array list of linked lists of integers would be the following:
0 [[1, 2]
1 []
2 [3, 6, 7]
3 [4, 5]
4 []
5 []
6 []
7 []
8 [1]
Storing the vertex indices rather than the names simplifies the depth-first search. The hash mapwould associate index 0 with ClassA, index 1 with ClassC and so on.
The directed graph class needs three public methods, one to initialize the graph each time a new file is read in, one to and an edge to the graph and one to generate a topological order given a starting index.
Finally checked exception classes should be defined for the cases where a cycle occurs and when an invalid class name is specified.
 olves writing a program that behaves like the Java commandline compiler. Whenever we request that the Java compiler recompile a particular class, it notonly recompiles that class but every other class that depends upon it, directly or indirectly, and ina particular order. To make the determination about which classes need recompilation, the Javacompiler maintains a directed graph of class dependencies. Any relationship in a UML classdiagram of a Java program such as inheritance relationships, composition relationships andaggregations relationships indicate a class dependency.The main class for this project should create the GUI shown below:The GUI must be generated by code that you write. You may not use a drag-and-drop GUIgenerator.Pressing theBuild Directed Graphbutton should cause the specified input file that contains theclass dependency information to be read in and the directed graph represented by thosedependencies to be built. The input file associated with the above example is shown below:ClassA ClassC ClassEClassB ClassD ClassGClassE ClassB ClassF ClassHClassI ClassCEach line of this file specifies classes that have other classes that depend upon them. The firstline, for example, indicates thatClassAhas two classes that depend upon it,ClassCandClassE. In the context of recompilation, it means whenClassAis recompiled,ClassCandClassEmust be recompiled as well. Using graph terminology, the first name on each line is thename of a vertex and the remaining are its associated adjacency list. Classes that have no
Attachments: