-1

Hey everyone,
I am having a small problem with sorting objects.
I have a method called organizeTank. It should sort the fish in the tank such that: (1) all dead fish come first sorted according to size in descending order, (2) all live fish come next such that herbivores come first sorted according to size in descending order and carnivores come next sorted according to speed in ascending order.

          {specie, size, speed, type, condition}
fish[0] = {"shark", 3, 7, "herbivore", true};
fish[1] = {"cat fish", 6, 10, "herbivore", false};
fish[2] = {"gold fish", 5, 7, "herbivore", true};
fish[3] = {"cat fish", 10, 8, "carnivore", true};
fish[4] = {"shark", 6, 10, "herbivore", true};
fish[5] = {"gold fish", 1, 4, "herbivore", false};
fish[6] = {"cat fish", 2, 6, "herbivore", false};

I will have to sort these objects according to the instructions, how do I that using selection sorting?

Thanks for your help!

Edited by mike_2000_17: Fixed formatting

4
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by stultuske
0

@decade
... and how will Arrays.sort(fish); work?
how is it going to compare the elements to see in which order they should be ordered?
@htmler
I would recommend you to check on tekashyap's answer and the links he provided.

if you want to use Arrays.sort(fish), as decade suggested, you will have to implement the compareTo method of the Comparable interface, in which you can declare how your elements should be sorted.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.