-
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
public void addBuilding (Building leftover)
{
if (extra == null || numberofBuilids > maximum)
{
return;
}
build[numberOfBuilds] = extra;
numberofBuilds++
}
then I create a new Building instance
eg
public Building createBuilding()
{
String name;
double type;
double insu;
Building build;
for (int i = 0; i < maximum; i ++)
{
name = Keyboard.readString "Name: ")
insu = Keyboard.readDouble("Insurance ")
type = Keyboard.readBuilding ("type")
}
if (type == 1)
{
build = new House(name, type)
}
if (type == 2)
{
buid = new Flat (name, type)
}
} return build;
}
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 .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks