Answered step by step
Verified Expert Solution
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
- First create a new project and call it TreesWithGenericComparables.
- Add a second class to your project called TreeMaster (no code needs to go in this class for the inlab)
- Add a third class called Node( no code needs to go in this class for inlab)
- You will need to create a fourth class called Dog that implements Comparable.
- The Dog class will have three instance fields that will represent adorable dogs (I watched Top Dog trials last night):
- A Breed (in your data use: Sheppard, Bulldog, Labrador, Mutt)
- A Color (in your data use: Brown, Black, Golden, Mixed)
- A Name (these should be distinct names)
- 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.
- Create a toString method to logically output the String to represent the data in the Dog class.
- 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.
- 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.
- Keep the code above and create two new instances of the Dog class with same breed, but everything else different, test again both ways.
- 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.
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started