COP 3538 – Data Structures with OOP
Project 4 – Summer 2012
Due: Class Time Monday, 23 July 2012
Binary Trees
Using NetBeans 7.1 or later version, you are to write a Java program using OOP
principles to accommodate the following functionality
Assignment #4
Provide student with experiences with generation of random numbers.
Provide student with expanded exercises in UML
Provide student with exercises in Javadoc and its various formats
Provide student with exercises in building a binary tree with object nodes
Provide student opportunity to display binary trees in various traversals
Provide student with experience in inserting and deleting node contents
of binary trees.
Task 1: Generate Random Numbers.
Using Java’s built in random number generator, you are to generate a sequence of
20 random non-negative integers (non-negative implies that zero is acceptable)
ranging 0 to 50. Let your first three numbers be 25, 12, and 37. Then use the
Random Number generator to generate seventeen more. As you build these
numbers, you are to push them into a stack using standard stack operations.
(Please note that you should allocate space for thirty random numbers, in case I
varying the number of input numbers required. You are to use an
InputOutputClass to accommodate building the stack of random integers, and
whatever additional methods are ‘appropriate’ for processing this stack. Note:
Do not push the 25, 12, and 37 onto the Stack. These will be the first three
numbers used to build the tree. Thus the intention is for 25 to be the root, 12
its left successor and 37 its right successor. Equivalently, you may, after
generating 17 numbers, push 37, 12, and 25 onto the stack.
Task 2: Display the Stack of Random Numbers.
Using an appropriate header, such as Generated Random Numbers, display
five at a time, left justified. Skip a line or two after displaying the last set of
Task 3: Build a Binary Search Tree.
From the stack of integers, you are to build a binary search tree. Recognize that
your tree may not look pretty and may be skewed left or right. It is quite unlikely
it will be any where near balanced.
Task 4: Display the Binary Search Tree. (Recursive NLR Scan)
You are to display the tree using a recursive NLR scan. The format is to contain
a header, left justified on the display line that contains the entries: Recursive
NLR Scan followed by a blank line followed by the list of integers left justified.
Skip a line after displaying the last integer.
The format should be
Continue in columnar fashion printing recursively (that is, NLR)
Task 5. Display the Binary Search Tree (Recursive LNR Scan)
Display the binary search tree using a recursive LNR scan.
The format should be
n = some number etc
Continue in columnar fashion printing recursively (that is LNR) Format as above.
Remember that when you print the node, relative to that node, it is considered N for that
subtree; that is, the first L that is printed must be considered N for that node and its left
and right subtree will be null.
Task 6: Display the Binary Search Tree. You are to display the tree using an iterative
NLR scan.
Same formats as in Task 4. But your first header says: Iterative NLR Scan.
Task 7: Display the binary Search tree using an iterative LNR scan.
Same format as in Task 5.
Task 8. Display the binary search tree using an iterative RNL scan. (This is tricky)
Same formats as above. Format will be same. Use the RNL scan to drive your printing.
Task 9. Display the binary search tree using an iterative LRN scan. (This too can
be tricky) Same formats as above, but sequence will be LRN nodes. But print with same
header: N L R.
Task 10. Delete from Binary Search Tree. (Now the fun parts.) You are, using your
InputOutput class and appropriate method (you design) in this object, to prompt me for
an integer to delete. You are to continue to prompt me for inputs and take the actions
below until I submit a -1 to you, at which time your program is to gracefully terminate.
Given your NLR scans, I can easily (you can too!) see what tree nodes are leaves, those
with one child, and those with two children. I will submit inputs to you one at a time in
all three categories. You are to echo print my input to you, delete the indicated node, and
print the resulting tree in recursive LNR format, which you have done before. Make the
results of this clear to the client (me). Your LNR scan will be used to verify you have
deleted the node requested.
You are to zip all files in your P4 as expected and Send them to be via the
assignment tab using the same naming conventions as in P0. Be certain your zipped file
runs! Please note: use zip files. If you use .rar files, I do not guarantee we can
grade – and this is bad. For UML, you may use Word, Power Point, or SmartDraw
Unzip it and run it locally before you send it to me. If it does not work, I cannot grade it.
Good testing? Ask a colleague to test your program for you!!
Grade Sheet for Program 4 – Trees
Name: __________________
Grade: __________________
Source Code – 10 points _________________________________
Indentation; Internal comments
Scope terminators; Choice of attribute names, etc.
Program Design – 30 points _____________________________
UML …………………………………………………………………… 10 points
Be sure to include all elements of the entrees – visibility, parameters, etc.
Detail Design …………………………………………………………… 20 points
Provide pseudocode for class that contains all the tree scan methods. This
needs to be well done. I will look at this carefully.
Javadoc – 10 points - ____________________________________points
No excuse to not have this wonderful this time! Remember, all
methods require @param and @return.
Appropriateness and completeness of comments
ALL methods must have Javadoc comments up front that are meaningful, please.
Outputs – 50 points
Accuracy and Format. All functionality present!
Skip lines in between displayed outputs as described above. .
Include headers / descriptors as described.
 If your program does not contain all the functionality required, you cannot expect a
grade above 60, that is a ‘passing grade.’ Please note that this will be rigidly enforced.
Program must be on time for full credit.
Bonus - 5 points for each feature you incorporate into your program. You will
need to include code that checks to see if my inputs to you are appropriate nonnegative integers; do not allow duplicates; diagnose not found nodes to be deleted;
any other reasonable edit. Code to handle these error conditions should likely be
handled via a try…catch sequence. (At the time of this writing, there is a potential
for fifteen bonus points)
Start early and do this a little at a time.
Always have a working product (not necessarily a product that contains all the
Remember, work smarter not harder.