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
*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
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 treeStep 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