Oluwatobi L.

asked • 03/15/21

Modify the Cage class to implement Comparable.

The definition of the Comparable interface can be found here. Remember that Comparable has one abstract method, int compareTo(T o). Two Cages can be compared based on their size obtained via getSize(). You must (1) implement the interface, and (2) define the compareTo method.


public class Cage <P extends Pet> {

private int size;

private P pet;

public Cage(P p, int s) {

size = s;

pet = p;

}

public boolean checkSize() {

if (pet.getSize() > size) {

return false;

}

return true;

}

public int getSize() {

return size;

}

public P getPet() {

return pet;

}

}


1 Expert Answer

By:

Patrick B. answered • 03/16/21

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.