Jump to content

Java: Multiple Class Interactions

Euphoric
 Share

So to simply this I'm going to put a majority of this in words to prevent the massive line spam of code that I've created thus far. What I have is a variable c from my Class Criteria. I have a class House that has a method satisfies that literally tells me true or false if the values given through c meet what someone is looking for. I'm wondering if I can call the method satisfies from House in HouseList or if I have to go about other methods to do this. If I have to I will add the other classes, its just quite a bit of a mess as I haven't annotated thoroughly yet or cleaned it up. Thanks for the help in advance! 

package Assignment01;import java.util.ArrayList;public class HouseList {	ArrayList<House> houseList; 	public HouseList(String houses)	{			}	public void printHouses(Criteria c)	{		for (int k = 0; k < houseList.size(); k++)		{			if()//Checks House.satisfies with Criteria c. 				System.out.println();		}	}	public String getHouses(Criteria c)	{		String listHouses = " ";		return listHouses;	}}
Link to comment
Share on other sites

Link to post
Share on other sites

You can call the method of the House object as long as it is public or in the same package as HouseList (and obviously not private) in this case.

 

The assignment seems to be about iteration over an ArrayList. I would advise using a for-each structure:

for ([your class] [index variable] : [the variable that holds your ArrayList]){[your logic here]}

The index variable is how you address the House in each iteration of the loop, using the get() method of ArrayList.

 

http://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html

 

Now that I think about it, I can't remember if you would need to use get() or not, it's been a while.. double edit: you don't, treat the index variable as the variable holding the house object you want to send a message to.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×