Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Your task in this question is to write a class called SkillTree which extends BasicMAryTree 2 8 0 ( an m - ary tree of
Your task in this question is to write a class called SkillTree which extends BasicMAryTree
an mary tree of Skill objects; a complete Skill.java is provided A template for the SkillTree
class is provided. It contains a constructor and a couple of useful methods. You will add additional
methods to this class in the following steps, which you should complete in order:
a Write a main method in the SkillTree class in which you construct your own skill tree for your
own hypothetical video game. Your tree must contain at least skills. However, for the sanity
of everyone involved, try to keep it under skills. Be creative! There is no reason why any
two students should hand in exactly the same or even very similar skill trees, nor should you
just duplicate the skill tree shown in the sample output. Print your tree to the console using the
toStringByLevel method inherited from BasicMAryTree
b Write a method in the SkillTree class called skillDependencies which takes a skill name as
input and returns an instance of LinkedList which contains all the of the skills which
are prerequisites for obtaining the input skill including the input skill itself! A RuntimeException
exception should be thrown if the tree does not contain the given skill. A good implementation
approach for this method is to use a recursive traversal of the tree to find the named skill, and
then add skills to the output list as the recursion unwinds. Tutorial includes some discussion of
recursive traversal of mary trees. Add to your main program a few tests of this method, and
print out the lists that is returned you can use the lists toString method for this Be sure to
test the case where the named skill does not exist in the tree.
c Write a method in the SkillTree class called skillTotalCost which takes a skill name as in
put and returns the total number of skill points that a player must invest to obtain the given
skill. If the named skill is not in the skill tree, then the skillTotalCost method should throw
a RuntimeException exception. Hint: this method is quite easy to implement if you make use of the
previously implemented skillDependencies method.
For example, in the above skill tree, if a character wants the Shield Ally skill they would need to
spend skill point to get Shield Proficiency, and then spend skill points to get Shield Ally for an
In the video game world, the term skill tree sometimes refers to things that actually arent trees; a noteworthy example is the
skill tree in the ARPG Path Of Exile, which, if you click the link, can see is clearly not a tree, even though they call it that. Here in
question we used the term skill trees to mean skill trees that are, in fact, actual trees.
Page
overall investment of points, so for the above tree, skillTotalCostShield Ally"
should return Note that the Skill object contains the cost of the skill.
Add to your main program a few tests of skillTotalCost, and print out the total costs returned.
Be sure to test the case where the named skill does not exist in the tree.
d Run your main program. Cut and paste the console output to a text file and submit it with your
assignment. See the sample output below.
Sample Output
Here is an example of what the output of your program might look like. Remember, you are ex
pected to be creative in designing your skill tree, and your submission should not attempt to duplicate
what you see here aside from the general formatting the formatting can be the same, but the data
should be different! Note that the formatting of output of the skill tree contents is done by the
toStringByLevel method of BasicMAryTree
import liblist.LinkedList;
import libtree.BasicMAryTree;
import libtree.LinkedSimpleTree;
import libtree.MAryNode;
public class SkillTree extends BasicMAryTree
Create libtree with the specified root node and
specified maximum arity of nodes.
@timing O
@param x item to set as the root node
@param m number of children allowed for future nodes
public SkillTreeSkill x int m
superxm;
A convenience method that avoids typecasts.
Obtains a subtree of the root.
@param i Index of the desired subtree of the root.
@return the ith subtree of the root.
public SkillTree rootSubTreeint i
return SkillTreesuperrootSubtreei;
This class stores the data for a single skill in a
skill libtree for a hypothetical video game.
public class Skill
String skillName;
String skillDescription;
int skillCost;
SkillString name, String desc, int cost
this.skillName name;
this.skillDescription desc;
this.skillCost cost;
public String toString
return skillName Cost: skillCost;
@return the skillName
public String getSkillName
return skillName
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started