Question: In Person.java on line 2 7 this is not correct: return Objects.equals ( name , person.name ) ; Names can be compared like this: name.equals

In Person.java on line 27 this is not correct:
return Objects.equals(name, person.name);
Names can be compared like this:
name.equals(person.name)
but you also need to compare heights and weights, which can be compared using ==
height == person.height
and
weight == person.weight
You need to cite sources for where ever you're referencing for this code.
Main should still read in the data from file, just as it did the first time this assignment was given without the tree, but this time the data should be put in a tree instead of in OrderedSet or ImperialSet.
The tree looks fine, but the comments are indented weirdly. Fix the indentation and MAKE SURE TO CITE YOUR SOURCES.
Using this code
public class Main {
public static void main(String[] args){
SortedTreeSet tree = new SortedTreeSet();
// Adding sample people
tree.add(new Person("Mario",155,90));
tree.add(new Person("Luigi",158,83));
tree.add(new Person("Bowser",310,726));
tree.add(new Person("Toad",41,7));
tree.add(new Person("Peach",183,60));
// Trying to add duplicates (shouldn't be added)
tree.add(new Person("Mario",155,90));
tree.add(new Person("Peach",183,60));
// Print the tree (in sorted order)
System.out.println("Sorted Tree Set:");
System.out.println(tree);
}
}
AND THIS ONE
public class Person {
private String name;
private int height;
private int weight;
public Person(String name, int height, int weight){
this.name = name;
this.height = height;
this.weight = weight;
}
public String getName(){
return name;
}
@Override
public String toString(){
return name +"("+ height +"cm,"+ weight +"kg)";
}
@Override
public boolean equals(Object o){
if (this == o) return true;
if (o == null || getClass()!= o.getClass()) return false;
Person person =(Person) o;
return Objects.equals(name, person.name);
}
}

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 Programming Questions!