Question: They will model their network as a tree with two types of nodes: Nintendo Nodes (these are always leaves, and represent one Donkey Kong player
They will model their network as a tree with two types of nodes: Nintendo Nodes (these are always leaves, and represent one Donkey Kong player with their Nintendo64 device), and Raspberry Nodes (these represent Raspberry Pis, which are used as routers in our network). They want to be able to view their network topology at any time, load and save it from a file (so they can occasionally restart their computer), add nodes, remove subtrees.Finally, sometimes routers and Nintendo 64s go down, so each device will have a boolean for broken. The final function will be to identify the root of the minimal subtree that contains all the failures for a given scenario When we load the file, we will assume that all nodes are working, and no node can contain more than 9 children. Each line will contain a position string, as well as a node name. If they are separated by a dash, the node is a Nintendo. The tree will be given and should be saved in preorder.
Here is a sample text file (format: position in tree, space, component type, a space character, text of component (if applicable), newline).:
XXX
1Central
11Mendy
111-Irving
112-Grey
113-LDS
2Hill
21Tabler
211-Tosc
212-TAC
213-Hand
22Roth
3West
31WestApartments
32-GLS Center
4-BasementClub
NetworkNode
Write a fully documented class called NetworkNode which holds the type of component being represented, an array of children (null if this will be a Control), and string for the text (null if this is a Container). Be sure to include all getters and setters. You may find it helpful to write helper methods, especially to check input before adding a child to the tree. Defining custom exceptions for actions like trying to add too many children to a node, or adding a child in an invalid position may also be desirable.
private String name
private boolean isNintendo
private boolean isBroken //default is false
private NetworkNode parent
private NetworkNode[] children there should be no holes in the array.
final int maxChildren=9 //A full node exception may be desirable.
NetworkTree
Write a fully documented class called NetworkTree which will serve as the tree manager for your NetworkTree. This must hold references into a tree (the root and cursor), as well as be able to generate and save the tree to and from a file. Again, defining some custom exceptions may be helpful for code readability.
private NetworkNode root
private NetworkNode cursor
public void cursorToRoot()
Sets the cursor to the root of the NetworkTree
public NetworkNode cutCursor()
Removes the child at the specified index of the NetworkTree, as well as all of its children.
Cursor goes to parent
Cutting root clears the tree
public void addChild(int index, NetworkNode node)
Adds the given node to the corresponding index of the children array.
Should throw an exception if adding the node at the specified index makes a hole in the array.
public void cursorToChild(int index)
Moves the cursor to the child node of the of the cursor corresponding to the specified index.
public void cursorToParent()
Moves the cursor to the parent of the current node.
public static NetworkTree readFromFile(String filename)
Generates the NetworkTree based on the file name that is passed in.
public static void writeToFile(NetworkTree tree, String filename)
Generates a text file that reflects the structure of the NetworkTree.
The format of the tree of the file should match the format of the input file.
public void cursorToMinimalBrokenSubtree()
The cursor should be on a node where all of the broken nodes are either the cursor or descendants.
There may not be such a node in the subtree.
Accompanying method: public void changeCursorBrokenStatus()
NintendoNetwork
Write a fully-documented class named NintendoNetwork that takes in a text file, generates a NetworkTree and provides an interface for a user to manipulate the tree. Please see the UI required functions for the required functionality
public static void main(String[] args)
The main method runs a menu driven application which first creates a NetworkTree based on the passed in file and then prompts the user for a menu command selecting the operation. The required information is then requested from the user based on the selected operation. You can find the list of menu options in the UI required functions section.
NetworkTree tree;
Smaple: Menu:
L- Load from file
P- Print
C- Cursor to child (index number)
A- Add child (index, type, prompt for text)
U- Cursor up (to parent)
X- Cut/Delete cursor
V- Paste Subtree (index number)
R- Cursor to root
S- Save to Text File
M-Cursor to root of minimal subtree containing all faults
B-Mark cursor as broken/fixed (flip the state)
Q - Quit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
