Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Download the zip file and import it on netbeans complete LinkedTree You must implement the following methods in LinkedTree.java: getRootElement(), addChild(), Contains(), and countDown() getRootElement()

Download the zip file and import it on netbeans

complete LinkedTree

You must implement the following methods in LinkedTree.java: getRootElement(), addChild(), Contains(), and countDown()

  • getRootElement(): This method returns the element held by the root.
  • addChild(): This method has two overloading methods (corresponding to the same function name but with different parameter lists); you will implement both.

The first overloading addChild() method takes a generic T parent and T child, invokes the existing method findNode() to locate the parent MultiTreeNode which holds the given element parent, and then, invokes another addChild method to add the child element into the located parent node.

The second overloading method takes a MultiTreeNode parent and the T child element. Its job is to construct a MultiTreeNode which holds the child element, then call the node's own addChild() method to append this new child node into its children list.

If the given parent element cannot be found, an ElementNotFoundException should be thrown.

Here we do not care about whether the child element is duplicated within other sibling child nodes of the same parent node. Nothing will be done if the given child element is null.

  • Contains(): This method would invoke the findNode() method to determine if the tree contains a T target element.
  • countDown(): This method is a private helper method for the size method; it will use recursion to count the number of nodes in the tree.

Summary

In this project, you'll be implementing methods for a LinkedTree, a data structure for generic elements held in a tree format (note that this is NOT a BINARY tree - it is a MULTINODE tree, so each node can have any number of children nodes). You'll also be implementing a method in PyramidScheme.java, which is an extension of a LinkedTree specifically for Person elements and includes logic that is representative of a real pyramid scheme.

In a pyramid scheme, each person tries to recruit people. Those people pay to join, and then try to recruit their own people. The money from those who join trickles up the tree to the person who started the pyramid scheme. The earlier you get in on it, the more money you can make. But this is illegal, and the higher up you are in the scheme the more legal trouble you will get in. So, in the PyramidScheme, each new recruit causes people higher up in the tree to earn more money. And then there is a point in the simulation where the whole pyramid scheme collapses. The project can be used to help prove the improper structure of the pyramid economy model.

Your job in the PyramidScheme code is to implement a method that returns the chain of people who should get a portion of the money when a new recruit is added.

The following is a diagram of the PyramidScheme made using the default parameters ($25.00 recruit price, 10% paid up):

Let us see how the recruitment fee of $25 for Person 12 flows back to his recruiter Person 9, up to Person 1 in the recruiting line.

Person 12 lost $25, the recruitment fee, and they give the $25 to Person 9; Person 9 keeps 90% of the $25 and gives his recruiter Person 4 the remaining 10% of $25; Person 4 receives $2.5, keeps its 90%, contributes the remaining 10% to his recruiter Person 1; thus, Person 1 receives 0.25. The updated balance of a person is computed as their previous balance plus the amount of money that he receives and minus the amount of money that he gives out.

Once you have all the code implemented you will be able to run the simulation and play around with the prices and see what happens within the pyramid scheme. In the simulation, we always end by collapsing the pyramid scheme (and then the people at the top end up in a lot of trouble).

The methods you implement in LinkedTree should be short and not more than 5 lines, or else you might be doing it wrong

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions