Question: Task 6.1 Trees are built up using nodes. Each node contain: a data element: a reference to a generic type T a left node: a

Task 6.1

Trees are built up using nodes. Each node contain:

a data element: a reference to a generic type T

a left node: a reference to the left sub-tree of type Node

a right node: a reference to the right sub-tree of type Node

Create a Java classNodewhich contains the above information. Implement reasonable settersand getters in your Node class.

Test out your class by creating nodes and calling various methods on the nodes in the main method.

Task 6.2

Create a class Tree to model a binary tree. This class should contain a single reference to theroot node of the tree. Implement reasonable setters and getters in your Treeclass.Again, test out your class by creating a tree and nodes objects; and by calling various methodson them in the main method.

Task 6.3

Write the methodconstruct Tree() in theTree class and create the following tree to find out if a person is fit or not? We assume the root node starts with the following question: age30? You need to insert to the left when the response is no and to the right when the response is yes.

Age < 30? -> no yes -> fit unfit. Exercise in the morning?-> no yes -> fit unfit. Eat Junk Food? -> no yes -> fit unfit.

Note: the above scenario does not suggest anything and it is solely for the purpose to practisea creation of a Binary tree.Once created, write a program to print the Binary tree to test the implementation of the treecreation.

Challenge Task 6.4

Write a function to take an input on users age and depending on the answers take another inputto see if they exercise or eat junk food. Based on the inputs, search the created Binary tree to find if they are fit or unfit. Hint, you can use a pre-order Traversal to solve this task

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!