Need help with this Strings/Methods question! class Dinosaur( private int height
ID: 3702677 • Letter: N
Question
Need help with this Strings/Methods question!
class Dinosaur( private int height; // The height of a dinosaur in feet private int weight; // The weight of a dinosaur in pounds private String color; //The color of the dinosaur public Dinosaur (int height, int weight, String color)( this.height - height; this.weight - weight; this.color - color; public Dinosaur (String color)( this. color = color; this.height - 0; this.weight - 0; public void eat(int mass) if(isNegative(mass)) return; this.weight +- mass; public void grow(int amount)H if (isNegative(amount)) return; this.height +- amount; private boolean isNegative(int value)I if (valueExplanation / Answer
In Dinosaur class equals method is present which returns true or false by checking with the passing object.
public static int numEquals(Dinosaur dino,Dinosaur[] arr)
{
total_count=0; // total_count to count how many objects equals
boolean stat=false; //setting boolean variable for status of objects equal or not
for(int count=0;count<arr.length;count++) //iterating dinosaur array objects
{
stat=dino.equals(arr[count]); //calling equals method checking objects equal or not
if(stat==true) //checking equals method return value is true or not
total_count=total_count+1 //incrementing total_count
}
return total_count //returning total_count of equal objects
}