Hello!
Have you heard of the interface Comparable?
It allows you to compare like-objects with its implementation.
public static void sort(Comparable[] values, int start, int end)
If your class implemented Comparable you would be forced to include a method called compareTo(Object o)
The reason this is nice is because the compiler recognizes anything that implements the interface as a Comparable object, which means you can use an array of any objects you want for the argument of the method above so long as they implement Comparable.
You will need to override this method since it does nothing on its own. You can make some attributes for it, like so--
//Method to be included in your Property class
public int compareTo(Object arg) //comparing to another object (a different Property)
{
if(arg instanceof Property) //if the object is-a property object
{
Property temp = (Property)arg; //Edit
if(temp.propertyValue == propertyValue)
return 0;
else if(temp.propertyValue < propertyValue)
return 1;
else return -1;
}
return 99;
}
Now you can sort different property objects using the compareTo method. If you compare two Property objects and the value (from the method) returned is -1, you know that the class that used the compareTo method has a lesser property and should be placed before the class it was comparing to.
On the other hand, if the value is 1 then you know that the class that used the compareTo method has a greater value and should come after the class it was comparing to.
If the result is zero then both classes have equal Property value and whichever ones comes before the other doesn't really matter in terms of sorting.
From there, all you have to do is making a condition to how the objects will sorted. Use a for loop to iterate through the objects and use the compareTo method that each object should have (since they implement Comparable).
Edit: Had to place a necessary cast from Object down to Property. See the edited code above.