How do I build a tree from categories of hurricanes and answer queries on the tree in java with a Tree class that has a linked structure of tree nodes and supports (at least) the following operations: • addChild(parentNode, childNode) // to maintain alphabetical/lexicographical order of the children • getChildren(node) • getParent(node) For each node, you may not assume it has a fixed or maximum number of children. Input: Input is from the command-line arguments in this order: 1. the first line has the top cateogory (hurricanes), followed by its sub-categories (e.g. cat1, cat2); each of the following lines has a category, followed by its sub-categories. 2. each line has one of the following queries: • GetNamesByCategory category • GetNamesByState state • GetNamesByCategoryAndState category state • GetNamesWithMultipleStates • GetNamesWithMultipleCategories • GetCategory name • GetState name You may assume each query is valid (name, category, and state exist in the data), but some queries do not have results. Output: Output goes to the standard output (screen), each line has an answer with the corresponding query: • GetNamesByCategory category name1 name2 ... • GetNamesByState state name1 name2 ... • GetNamesByCategoryAndState category state name1 name2 ... • GetNamesWithMultipleStates name1 name2 ... • GetNamesWithMultipleCategories name1 name2 ... • GetCategory name category1 ... • GetState name state1 ... Note that a hurricane can create hurricane conditions in more than one state in different categories, so GetState/GetCategory might have more than one state/category and getNames should not have duplicates. All results should be alphabeti- cally/lexicographically ordered. Report “none” if there are no results.
How do I build a tree from categories of hurricanes and answer queries on the tree in java with a Tree class that has a linked structure of tree nodes and supports (at least) the following operations:
• addChild(parentNode, childNode) // to maintain alphabetical/lexicographical order of the children
• getChildren(node)
• getParent(node)
For each node, you may not assume it has a fixed or maximum number of children.
Input: Input is from the command-line arguments in this order:
1. the first line has the top cateogory (hurricanes), followed by its sub-categories (e.g. cat1, cat2);
each of the following lines has a category, followed by its sub-categories.
2. each line has one of the following queries:
• GetNamesByCategory category
• GetNamesByState state
• GetNamesByCategoryAndState category state
• GetNamesWithMultipleStates
• GetNamesWithMultipleCategories
• GetCategory name
• GetState name
You may assume each query is valid (name, category, and state exist in the data), but some queries do not have results.
Output: Output goes to the standard output (screen), each line has an answer with the corresponding query:
• GetNamesByCategory category name1 name2 ...
• GetNamesByState state name1 name2 ...
• GetNamesByCategoryAndState category state name1 name2 ...
• GetNamesWithMultipleStates name1 name2 ...
• GetNamesWithMultipleCategories name1 name2 ...
• GetCategory name category1 ...
• GetState name state1 ...
Note that a hurricane can create hurricane conditions in more than one state in different categories, so GetState/GetCategory
might have more than one state/category and getNames should not have duplicates. All results should be alphabeti-
cally/lexicographically ordered. Report “none” if there are no results.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 1 images