here's my problem. I've got 3 classes: one called Pets, one Pet and one PetActions.
In my Pet-class I've three variables: String name, int weight, int height and a constructor.
In my PetAction-Class I've got my main methode. In it I'm creating 5 Pet-Objects
Pet cat = new Pet ("cat", 4, 25);
Pet dog = new Pet ("dog", 24, 58);
Pet bird = new Pet("bird" , 0.3, 18);
Pet snake = new Pet("snake", 2, 150);
Pet rabbit = new Pet ("rabbit", 2, 40);
These I'm packing in a Pet- Array
Array[] pets = {cat, dog, bird, rabbit, snake};
Which I'm using to create a Pets-Object
Pets pets = new Pets(pets);
My Pets- Class looks like this:
public class Pets{
Pet[] pets;
public Pets(Pet[] pets){
this.pets = pets;
}
public int position(Pet pet) {
Pet[] sortedPets;
// search in sortedPets pet
return position;
}
public Verein getPetFromString(String s) {
return ;
}
Now, In my PetAction - class, I'm asking the user the position of which animal he wants to know (They are supposed to be sorted from lightes to heaviest, if two weight the same it checks the realtion between weight and height), and here comes my problem. I just don't understand how this is supposed to work properly. I know I have to use Comparable and Comporator (at least that's what I read online), but I don't manage to properly take an example and proceed with it. Maybe also due to the language barrier. Can somone help me please? (: