New to arrayLists and confused.
I have 2 classes. One is Property the other is Letting Agent.
Property creates property objects with 7 private variables. Letting Agent creates an arrayList of property objects.
I have managed to use external method calls to methods in the Property class in the Letting Agent class to update objects in my arrayList.
Now I am trying to implement a property search method in Letting Agent that takes 3 parameters and checks them against 3 of the fields of each object in my arrayList until one that matches all three is found. I am doing this using a while loop.
The problem I am having is that the while loop needs to contain an if/else statement that performs comparisons of the 3 parameters taken when the method is called to the values stored within the fields of that object.
public void propertySearch( char location, double maxMonthlyRent, int minNumberOfBedrooms)
{
int index = 0;
boolean propertyFound = false;
while(!propertyFound && index < properties.size())
{
Property property = properties.get(index);
if(location == property.location && maxMonthlyRent >= property.monthlyRent)// and same for bedrooms
{
property.displayProperty( // this method is in my Property class
propertyFound = true;
}
else
{
index++;
}
}
The problem is that I cannot perform my comparison as the fields of the Property class are private and I amsure that they were supposed to stay this way. Is there another way of me performing my if/else statement against the fields of the objects in my arraylist in the Letting Agents class?
I ONLY need to perform a comparison not actually alter the data stored in the fields in any way so I was thinking that there might be a way of getting the values of the fields that I am overlooking.
This has me really stuck so would really appreciate it if someone can give me kick in the right direction. Please ask me if you need to know more.
Thanks