If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

search through objects of arrays

Hi,
I have an abstract class called Building, and two sub classes called Flat and House, and a class called BuildingSystem. Constructors, instance variables are all there. In this class, Building System I have an array called Building [] build and each subclass has its own getValue() method.
In building System i have a method to add building to array

Now in a method that has to be called
public Building findHighestValue(int buildtype)
I want it to search through the property array, and return the highest getValue method for each type of building eg
If the buildtype was 1, i want to get the highest getValue() from the Flats and if it were 2 I want it to do the same except get highest of the House instances an for 0 i want t tot return highest of all. Any tips ? Thanks heaps .

something like this, will search for ONE highest value. you can use the idea, to expand to "if the building is a nhouse, change the int maxHouse else if its a Flat, change the int maxFlat)
When you have a method that finds the highest of both.. you should then assess what the user asked for.. was it house only? return the house max you found, else, was it the flat only? then retun the flat max you found, else was it highest of all? compare the flat and house maxes and return the larger

here is the generic process for finding one maximum:

Code:

//myObjects is an array of objectsint max = -1;
for(int i=0; i < myObjects.length; i++)
//if the object value is bigger than the max, set a new maxif( myObjects&#091;i&#093;.getValue() > max){
max = myObjects.getValue();
}
}