Question: This code should be in Java *UPDATED* This is the classes needed to finish this lab //TreeMaster.java public class TreeMaster { } //Node.java public class

This code should be in Java

This code should be in Java *UPDATED* This is the classes needed

*UPDATED*

This is the classes needed to finish this lab

//TreeMaster.java public class TreeMaster {

}

//Node.java public class Node {

}

//Dog.java class Dog implements Comparable{ private String breed; private String color; private String name; //constructor with fields public Dog(String breed, String color, String name) { super(); this.breed = breed; this.color = color; this.name = name; } //getter and setters. public String getBreed() { return breed; }

public void setBreed(String breed) { this.breed = breed; }

public String getColor() { return color; }

public void setColor(String color) { this.color = color; }

public String getName() { return name; }

public void setName(String name) { this.name = name; }

public int compareTo(Dog other) { //do albphabetical comparision on calling dog breed with passed dog breed. int res = breed.compareTo(other.getBreed()); //if breeds are not same return res. if(res != 0) { return res; }else{ //if breeds are same //then compare the this dog color with passed dog color. res = color.compareTo(other.getColor()); //if both colors are not same then return the comparision result. if(res != 0){ return res; }else{ //if colors are also same then return the comparision of the names. return name.compareTo(other.getName()); } } }

@Override public String toString() { return "breed = " + breed + ", color = " + color + ", name = " + name; } }

//Main.java public class Main { /** * Description: * method to prints which dog(s) is more adorable. * Note that we have used alphabetical order to compare the breed,color and name of the two dogs. * @param one * @param two */ public static void printWhoseAdorable(Dog one,Dog two) { System.out.println(" Comparing dogs below dogs:"); System.out.println("Dog 1 : "+one); System.out.println("Dog 2 : "+two); int res = one.compareTo(two); //if result is 0, it means both dogs are same. //res is return in such a way that. //comparing breed, if breed is same comparing color, //if color is also same comparing name . all of them are compared using alphabetical order. if(res == 0) { System.out.println(" Dogs "+one.getName()+" and "+two.getName()+" are both Adorable."); }else if(res 0) { //if result is > 0 then dog two is more adorable than dog one. System.out.println(" Dog "+two.getName()+" is more Adorable than Dog "+one.getName()); } } /** * Description: method that swaps the two Dog objects and * prints them before and after swapping. * @param one * @param two */ public static void swapAndPrintDogs(Dog one, Dog two) { System.out.println(" Dogs before swapping: "); System.out.println("Dog 1 : "+one); System.out.println("Dog 2 : "+two); Dog temp = new Dog(one.getBreed(),one.getColor(),one.getName()); one.setName(two.getName()); one.setColor(two.getColor()); one.setBreed(two.getBreed()); two.setBreed(temp.getBreed()); two.setColor(temp.getColor()); two.setName(temp.getName()); System.out.println(" Dogs After swapping: "); System.out.println("Dog 1 : "+one); System.out.println("Dog 2 : "+two); } public static void main(String[] args) { //checking two dogs with different fields Dog one = new Dog("Sheppard","Brown","Tommy"); Dog two = new Dog("Bulldog","Black","Jimmy"); printWhoseAdorable(one,two); swapAndPrintDogs(one, two); System.out.println("-----------------------------------------------");

//checking two dogs with same breed and different color and name. Dog three = new Dog("Labrador","Golden","Miky"); Dog four = new Dog("Labrador","Mixed","Milky"); printWhoseAdorable(three,four); swapAndPrintDogs(three, four); System.out.println("------------------------------------------------"); //checking two dogs with same breed,color and different name. Dog five = new Dog("Mutt","Mixed","Johny"); Dog six = new Dog("Mutt","Mixed","Jamy"); printWhoseAdorable(five,six); swapAndPrintDogs(five, six); } }

What to for the OUT-LAB 1. Design and implement a class for the Node class closely related to the Node class I did in class, but created for a Tree instead of LinkedList This Node class should be using generics for it's data. . This class will need to have references to both it's children. . And it will need all the elements/methods to set, get those references as well . Plus methods to retrieve the data which will eventually get the String in the Dog Class created in toString() . You should know exactly where to go to find a very useful example to do all this stuff. 2. The data for this tree will be a Comparable class called Dog you created for the inlab this week. 3. Design and implement the TreeMaster class: The add method should be a recursive method based on the pseudocode given in the notes. . This will be similar to the LinkedList example I went over in class. TreeMaster should use Generics. One data member (or attribute) in this class it should be a reference variable to point to the root. No DUMMY variables needed like the linked list example. . You only add in order so there doesn't need to be the additional add methods, just one method to insert Dogs into the tree.. . You will need a remove method which will also be based on the pseudocode algorithm given during class. This class will need three print methods, inorder, preorder, postorder. Use the algorithms in the notes that I covered in class to create these print methods. 4. Update your driver to fill the tree with at least seven dogs and then test your three print statements. 1. Grading Criteria You will be graded in the outlab by the following: Programming style Insertion method working properly In-Order Display Pre-Order Post-Order Delete method Generics . Node and Tree Master should work with any Data class, not just Dogs. Comparing working What to for the OUT-LAB 1. Design and implement a class for the Node class closely related to the Node class I did in class, but created for a Tree instead of LinkedList This Node class should be using generics for it's data. . This class will need to have references to both it's children. . And it will need all the elements/methods to set, get those references as well . Plus methods to retrieve the data which will eventually get the String in the Dog Class created in toString() . You should know exactly where to go to find a very useful example to do all this stuff. 2. The data for this tree will be a Comparable class called Dog you created for the inlab this week. 3. Design and implement the TreeMaster class: The add method should be a recursive method based on the pseudocode given in the notes. . This will be similar to the LinkedList example I went over in class. TreeMaster should use Generics. One data member (or attribute) in this class it should be a reference variable to point to the root. No DUMMY variables needed like the linked list example. . You only add in order so there doesn't need to be the additional add methods, just one method to insert Dogs into the tree.. . You will need a remove method which will also be based on the pseudocode algorithm given during class. This class will need three print methods, inorder, preorder, postorder. Use the algorithms in the notes that I covered in class to create these print methods. 4. Update your driver to fill the tree with at least seven dogs and then test your three print statements. 1. Grading Criteria You will be graded in the outlab by the following: Programming style Insertion method working properly In-Order Display Pre-Order Post-Order Delete method Generics . Node and Tree Master should work with any Data class, not just Dogs. Comparing working

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!