in a project i am trying to get two or more agents to communicate between each other to collect things in the environment. to do this i am using a mailbox containing messages that they would respond to depending on the messages sent ebtween each other. below is where i create the linked list
mailbox = new LinkedList[numberOfAgents()];
for ( int i=0; i< numberOfAgents(); i++ ){
mailbox[i] = new LinkedList<Message>();
mailbox[i].add(new Message(i, knownBloodBanks, knownDonors));
}
and then the private message and intention classes
private class Message
{
// instance variables
private int senderId;
private BoardComponentList donors;
private BoardComponentList bloodBanks;
private BoardComponent requestAssistanceAt;
private Intention iIntendToAssistAt;
public Message( int senderId, BoardComponentList d, BoardComponentList b )
{
this.senderId = senderId;
donors = d;
bloodBanks = b;
} // end constructor
public void setIntentions( Intention intention )
{
iIntendToAssistAt = intention;
}
public void setRequest( BoardComponent bC )
{
requestAssistanceAt = bC;
}
public BoardComponentList getDonors()
{
return donors;
}
public BoardComponentList getBloodBanks()
{
return bloodBanks;
}
public Intention getIntentions()
{
return iIntendToAssistAt;
}
public BoardComponent getRequest()
{
return requestAssistanceAt;
}
public int getSenderId()
{
return senderId;
}
} // end Message class
private class Intention
{
// instance variables
private BoardComponent target;
private double distanceTo;
public Intention( BoardComponent bC, double distance )
{
target = bC;
distanceTo = distance;
} // end constructor
public BoardComponent getTarget()
{
return target;
}
public double getDistancetoTarget()
{
return distanceTo;
}
}
i cant for the life of me figure out how to access the methods inside the private class so that i can set goals and see the messages between agents. any help or pointers in the right direction would be greatly appreciated, i hope i've included enough info if not please let me know anything else needed
i didnt explain myself clearly as i so often find problems with but yes both the private classes and the first code snippet are found inside a public class
Sample code below ( modified your classes a bit because they we giving compilation error):
package com.pkg1;
import java.util.LinkedList;
public class Sample{
public Sample(){
LinkedList[] mailbox = new LinkedList[10];
for ( int i=0; i< 10; i++ ){
mailbox[i] = new LinkedList<Message>();
mailbox[i].add(new Message(i));
}
}
private class Message
{
// instance variables
private int senderId;
private Intention iIntendToAssistAt;
public Message( int senderId )
{
this.senderId = senderId;
} // end constructor
public void setIntentions( Intention intention )
{
iIntendToAssistAt = intention;
}
public Intention getIntentions()
{
return iIntendToAssistAt;
}
public int getSenderId()
{
return senderId;
}
} // end Message class
private class Intention
{
// instance variables
private double distanceTo;
public Intention( double distance )
{
distanceTo = distance;
} // end constructor
public double getDistancetoTarget()
{
return distanceTo;
}
}
}