43.8k views
5 votes
We need an equals method for the Dog class. It needs to give back to the caller a boolean value indicating whether another object of the same type's attributes are all of the same value as the calling object's. Provide the entire method (header and code), and only the method.

public class Dog {
private String name;
private int age;
private int [] healthScores;
}

User Ctusch
by
4.9k points

1 Answer

6 votes

Answer and Explanation:

Using Javascript:

Class Dog{

var healthScores=[];

Constructor(name, age, ...healthScores) {this.name=name;

this.age=age;

this.healthsScores=healthScores;

}

checkObject(new Dog){

If(new Dog.name===this.name,new Dog.age===this.age, new Dog.healthScores===this.healthScores){return true;

}

else{

console.log("objects are not equal");

}

}

}

To call the method checkObject:

var Tesa = new Dog(Tes,1,[45,46,82]);

var Bingo = new Dog(bing,2,[43,46,82]);

Bingo.checkObject(Tesa);

Note: we have used ES6(latest version of Javascript) where we passed the healthScore parameter(which is an array) to our constructor using the spread operator.

User David Artmann
by
5.8k points