Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

THIS IS A LAB FOR AP COMP SCI PLS HELP ME WITH THE ADD AND REMOVE METHOD, i HAVE

ID: 3623348 • Letter: T

Question



THIS IS A LAB FOR AP COMP SCI PLS HELP ME WITH THE ADD AND REMOVE METHOD, i HAVE ALREADY WRITTEN THE PET CLASS. ADD METHOD WILL KEEP ADDING ELEMENTS T AT INDEX 0, EACH TIME THRUGH THE LP, AND EVERY ELEMENT WILL MOVE UP ONE, LIKE IF I ADD 1 IN THE ARRAY AND SECOND TIME THROUGH I ADD A 2 THEN ARRAY WILL HAVE 21; AND THE REMOVE METHOD WILL FIND THGE INDEX OF THE ELEMENT TO REMVE AND MOVE OTHER ELEMENTS DOWN ONE. PLS HELP ASAP!!!!!



 




Below is the



Kennel class. It represents keeping pets in a kennel. Write the missing parts of the class.

public class Kennel

{

private Pet[] petList;

private int petsInKennel; // number of Pets in the Kennel

// the maximum capacity for a Kennel is 100 Pets

public Kennel()

{

// write this

}

// adds a Pet to the beginning of petList

// what happens to petsInKennel when you call the addPet method?

public void addPet(Pet pet)

{

//write this

}

// what happens to petsInKennel when you call the removePet

// method?

// removes a Pet from petList and moves all Pets after it

// down one index

public void removePet(Pet pet)

{

// write this

}

// prints the names of all the Pets in the Kennel on a single

// line with a space in between

public void printPets()

{

// write this

}

// make all the Pets in the Kennel speak

// on one line for each Pet, prints the Pet's name and the

// result of the call to its speak method

public void allSpeak()

{

//write this

}

}

 

 

 

 



You will have 6 different files for this lab. Your run should look like this:





Pets in the kennel: Kujo Lassie Benji Spot Jinx Tiger

Kujo says "bark" "bark"

Lassie says "bark" "bark"

Benji says "bark"

Spot says "bark"

Jinx says "meow"

Tiger says "meow"

Pets in the kennel: Kujo Benji Jinx Tiger

Kujo says "bark" "bark"

Benji says "bark"

Jinx says "meow"

Tiger says "meow"

 

Explanation / Answer

public class Kennel { private Pet[] petList; private int petsInKennel; // number of Pets in the Kennel // the maximum capacity for a Kennel is 100 Pets public Kennel() { petList = new Pet[100]; petsInKennel = 0; } // adds a Pet to the beginning of petList // what happens to petsInKennel when you call the addPet method? public void addPet(Pet pet) { petList[petsInKennel] = pet; } // what happens to petsInKennel when you call the removePet // method? // removes a Pet from petList and moves all Pets after it // down one index public void removePet(Pet pet) { // loop until you reach desired pet for(int i = 0; i