Question: Given the @D array in class AdoptionRunner: Pet [ ] [ ] pets = { { new Pet ( Dog , 2 )

Given the @D array in class AdoptionRunner: Pet[][] pets ={{new Pet("Dog",2), new Pet("Dog",5), new Pet("Dog",8)},
{new Pet("Hamster",1), new Pet("Hamster",2), new Pet("Hamster",3)},
{new Pet("Bird",5), new Pet("Bird",7), new Pet("Bird",12)}}; In the Adoption class, write the reversePets() method to reverse the elements in the row at the parameter index in the 2D array pets. public class Adoption {
private Pet[][] pets; // The 2D array of Pet objects
/*
* Initializes pets to the specified 2D array of Pet objects
*/
public Adoption(Pet[][] pets){
this.pets = pets;
}
/*
* Returns the 2D array of Pet objects
*/
public Pet[][] getPets(){
return pets;
}
/*
* Reverses the row located at index by swapping the first
* and last elements in the row
*/
public void reversePets(int index){
}
/*
* Returns a String containing the information for
* each Pet object in the 2D array pets
*/
public String toString(){
String result =""; for (int row =0; row < pets.length; row++){
for (int col =0; col < pets[0].length; col++){
result += pets[row][col]+"";
}
result +="
";
}
return result;
}
}

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!