Question: This code should be in Java Lab 1--Build a Binary Search Tree Due date: This lab has two due dates, the in-lab part will be

This code should be in Java

Lab 1--Build a Binary Search Tree

Due date: This lab has two due dates, the in-lab part will be due by end of lab, or at least progress toward completing the inlab by end of lab class, the outlab portion will be due in two weeks.

Purpose:

The purpose of this assignment is to have some practice using Comparables in classes.

The purpose of the follow-up outlab is to practice programming a tree from scratch using Generics.

  • This will be a binary tree, not a balanced search tree, just a binary tree.
    • .

What to do - IN-LAB part

  1. First create a new project and call it TreesWithGenericComparables.
  2. Add a second class to your project called TreeMaster (no code needs to go in this class for the inlab)
  3. Add a third class called Node( no code needs to go in this class for inlab)
  4. You will need to create a fourth class called Dog that implements Comparable.
  5. The Dog class will have three instance fields that will represent adorable dogs (I watched Top Dog trials last night):
    1. A Breed (in your data use: Sheppard, Bulldog, Labrador, Mutt)
    2. A Color (in your data use: Brown, Black, Golden, Mixed)
    3. A Name (these should be distinct names)
  6. Now you will create the compareTo method for comparison of the two objects. Include the compareTo method like in my robot or song examples
    • First, compare the dog's breed
    • Then if those are the same, the dog's color
    • Then if breed and color are the same use their name as the final distinction factor.
  7. Create a toString method to logically output the String to represent the data in the Dog class.
  8. In your main class, you created in step number one, you should write some code to test your comparisons. Do not use the TreeMaster, or Node class.
    1. Create a couple of instances of the Dog class that are completely different and call the compareTo method, get the return value back, check to make sure it's correct and coming from the right area of your compareTo method. Swap the two instances around and see if the value changes like it should.
    2. Keep the code above and create two new instances of the Dog class with same breed, but everything else different, test again both ways.
    3. Keep code above and create two more instances, same breed, and color, but different names, test both ways outputting the results to make sure all aspects are working.
  9. Run the code for your lab TA to make sure they see you've completed your work properly and then you are done with the inlab.

If you finish early and get everything working you can start working on your outlab. Use the time wisely

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!