Maurice Tutor

(5)

$15/per page/Negotiable

About Maurice Tutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Algebra,Applied Sciences See all
Algebra,Applied Sciences,Biology,Calculus,Chemistry,Economics,English,Essay writing,Geography,Geology,Health & Medical,Physics,Science Hide all
Teaching Since: May 2017
Last Sign in: 398 Weeks Ago, 2 Days Ago
Questions Answered: 66690
Tutorials Posted: 66688

Education

  • MCS,PHD
    Argosy University/ Phoniex University/
    Nov-2005 - Oct-2011

Experience

  • Professor
    Phoniex University
    Oct-2001 - Nov-2016

Category > Computer Science Posted 27 Aug 2017 My Price 15.00

StringBinaryTree

For this programming assignment you are to deliver an implementation of a Java class named StringBinaryTree that adheres to theStringBinaryTree API specification provided. Note that you may, but need not, extend the published API to include apublic static void main(String[] args) method to be used for stand-alone testing and demonstration.

Your submission should be a demonstration of your best effort at this time. Aim for code that is easy to read as well as correct. Your submission must match the syntactic specification of the API. Note that this assignment has a companion Virtual Programming Lab (VPL) activity that is required and which performs basic checks (file naming, compilation, API, style convention):String Binary Tree - VPL

You must submit a single Java source code file whose name is StringBinaryTree.java

 

###################################################

StringBinaryTree API Specification

StringBinaryTree API

 


Class StringBinaryTree


public class StringBinaryTreeextends Object

A simple binary tree whose root holds a non-null String value.

The StringBinaryTree datatype is defined recursively as being comprised of a value of type String, a reference to a left child of type StringBinaryTree, and a reference to a right child of type StringBinaryTree. As this datatype represents a binary tree, there must be no duplicate references nor any references to the root.

The empty tree is distinguished by the following properties:
numberOfNodes() == 0,
isEmpty() == true, and
height() == -1.

Terminology:

  • ancestor = a parent, grandparent, great-grandparent, etc.
  • descendant = a child, grandchild, great-grandchild, etc.
  • height = the length of the longest path to a leaf
  • internal = a tree with at least one child
  • leaf = a tree with no children
  • root = any StringBinaryTree object
  • tree = a StringBinaryTree with all its descendants

Constructor Summary

StringBinaryTree()
Construct an empty tree.

 

StringBinaryTree(String rootvalue)
Construct a tree with no children whose value is specified by the parameter.

 

StringBinaryTree(String rootvalue,StringBinaryTree leftchild,StringBinaryTree rightchild)
Construct a tree with specified value, left child, and right child.

 

 

Method Summary

StringBinaryTree

getLeftChild()
Return the left child of this tree.

StringBinaryTree

getRightChild()
Return the right child of this tree.

String

getValue()
Return the value of the root of this tree.

int

height()
Utility to determine the height of this tree; -1 if empty tree.

boolean

isEmpty()
Empty tree predicate.

boolean

isLeaf()
Leaf predicate.

int

numberOfLeaves()
Utility to determine the number of leaves of this tree.

int

numberOfNodes()
Return the number of nodes in this tree; 0 if empty tree.

void

setLeftChild(StringBinaryTree child)
Replace the left child of the root of this tree.

void

setRightChild(StringBinaryTree child)
Replace the right child of the root of this tree.

void

setValue(String value)
Modify the value of the root of this tree.

String

toString()
Render tree as a string.

 

Methods inherited from class

clone,equals,finalize,getClass,hashCode,notify,notifyAll,wait,wait,wait

 

Constructor Detail

StringBinaryTree

public StringBinaryTree()

Construct an empty tree.


StringBinaryTree

public StringBinaryTree(String rootvalue)

throwsIllegalArgumentException

Construct a tree with no children whose value is specified by the parameter.

Parameters:

rootvalue - the value stored at the root of the tree

Throws:

IllegalArgumentException - if parameter is null


StringBinaryTree

public StringBinaryTree(String rootvalue,

StringBinaryTree leftchild,

StringBinaryTree rightchild)

throwsIllegalArgumentException

Construct a tree with specified value, left child, and right child.

Parameters:

rootvalue - the value stored at the root of the tree

leftchild - the left child of the root;null if no such child

rightchild - the right child of the root;null if no such child

Throws:

IllegalArgumentException - ifrootvalue parameter is null

Method Detail

getLeftChild

publicStringBinaryTree getLeftChild()

throwsNullPointerException

Return the left child of this tree.

Returns:

the left child; null if no such child

Throws:

NullPointerException - if this tree is empty


getRightChild

publicStringBinaryTree getRightChild()

throwsNullPointerException

Return the right child of this tree.

Returns:

the right child; null if no such child

Throws:

NullPointerException - if this tree is empty


getValue

publicString getValue()

throwsNullPointerException

Return the value of the root of this tree.

Returns:

the value of the root

Throws:

NullPointerException - if this tree is empty


height

public final int height()

Utility to determine the height of this tree; -1 if empty tree.

Returns:

the height of this tree, -1 if empty


isEmpty

public boolean isEmpty()

Empty tree predicate.

Returns:

true if this is an empty tree;false otherwise


isLeaf

public boolean isLeaf()

throwsNullPointerException

Leaf predicate.

Returns:

true if this is a leaf;false otherwise.

Throws:

NullPointerException - if this tree is empty


numberOfLeaves

public int numberOfLeaves()

throwsNullPointerException

Utility to determine the number of leaves of this tree.

Returns:

the number of leaves

Throws:

NullPointerException - if this tree is empty


numberOfNodes

public int numberOfNodes()

Return the number of nodes in this tree; 0 if empty tree.

Returns:

the number of nodes


setLeftChild

public void setLeftChild(StringBinaryTree child)

throwsNullPointerException

Replace the left child of the root of this tree.

Parameters:

child - the new left child for this tree

Throws:

NullPointerException - if this tree is empty


setRightChild

public void setRightChild(StringBinaryTree child)

throwsNullPointerException

Replace the right child of the root of this tree.

Parameters:

child - the new right child for this tree

Throws:

NullPointerException - if this tree is empty


setValue

public void setValue(String value)

throwsNullPointerException

Modify the value of the root of this tree.

Parameters:

value - the new value for the root

Throws:

NullPointerException - if this tree is empty


toString

publicString toString()

Render tree as a string.

Overrides:

toString in classObject

Returns:

string rendering of this object

 

Here is the StringBinaryTree.java file

 

1 // StringBinaryTree.java

2 /**

3 * A simple binary tree whose root holds a non-null String value.

4 *

 

5 * The StringBinaryTree datatype is defined recursively as

6 * being comprised of a value of type String,

7 * a reference to a left child of type StringBinaryTree, and

8 * a reference to a right child of type StringBinaryTree.

9 * As this datatype represents a binary tree,

10 * there must be no duplicate references nor any references

11 * to the root.

12 *

13 *

 

14 * The empty tree is distinguished by the following properties:

15 * numberOfNodes() == 0,

16 * isEmpty() == true, and

17 * height() == -1.

18 *

19 *

Terminology:

20 *

  • ancestor = a parent, grandparent,

21 * great-grandparent, etc.

22 *

  • descendant = a child, grandchild,

23 * great-grandchild, etc.

24 *

  • height = the length of the longest path to a leaf

25 *

  • internal = a tree with at least one child

26 *

  • leaf = a tree with no children

27 *

  • root = any StringBinaryTree object

28 *

  • tree = a StringBinaryTree with all its descendants

29 *

30 * @author YOURNAMEHERE

31 * @version YOURVERSIONHERE

32 */

33 public class StringBinaryTree {

34

35 }

Answers

(5)
Status NEW Posted 27 Aug 2017 11:08 AM My Price 15.00

Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll

Not Rated(0)