Currently working on trying to have two objects interact with one another; such as having "people" (the objects) talk to each other. My question is, if I have generated two random objects, or "people" containing different attributes, how can I have them interact with each other in my class if they are both static? I am just not sure how to pass them to one another if I have to generate them in a static way.
To keep things simple, let's say I just want to have them introduce themselves. That is have person A say hello to person B, and have person B reply with "Hi Person A, my name is B".
Here is my generateAgent() method:
public class Agent {
public static Object generateAgent() {
//Create static object randomAgent
Agent randomAgent = new Agent();
//Create this agent's properties:
//1. Get a Gender/Name
randomAgent.getName();
//More Attributes below....
return randomAgent;
}
}
Here is my sayHelloTo()
method:
public void sayHelloTo(String name) {
//More Code here
return;
}
Then in my other java file how do I pass Object A / B (representing person A / B) to my Agent class if they are both static? I'm not sure what I am missing exactly.
public class DiscussionDirector {
public void discuss() {
//Create Two People:
Agent a = new Agent();
a.generateAgent();
Agent b = new Agent();
b.generateAgent();
//Have them introduce themselves:
a.sayHelloTo(); // ----> Not sure what parameters and such go here to pass successfully
return;
}
}