Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This code should be in Java The purpose of this assignment is to have some practice using Comparables in classes. The purpose of the follow-up

This code should be in Java

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.

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

Step: 3

blur-text-image

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

Data Analysis Using SQL And Excel

Authors: Gordon S Linoff

2nd Edition

111902143X, 9781119021438

More Books

Students also viewed these Databases questions