|
I'm trying to complete another assignment for my online course, and I'm having trouble getting it. I've learned about ArrayLists and HashMap in separate lessons but now I'm supposed to create a HashMap with an ArrayList as the "value". I am totally stuck. The program is supposed to be a simple MailServer and MailClient. I've done the MailClient and the MailItem classes but I'm having a lot of trouble with MailServer. I need to do a "post" method that take the info from the sendMessage info from MailClient and puts it into a HashMap, but the value should be an ArrayList of all the messages. Confusing!
Here is what I have so far... not sure if I need to post the MailClient code or not for help...
/**
* Add the given message to the message list.
* @param item The mail item to be stored on
the server.
*/
public void post(String name, MailItem item)
{
ArrayList list = new ArrayList();
messages.put(name, item);
}
the "name" parameter should be the user name which is set when you create a MailClient object.
Now I know this isn't correct, any help appreciated.
maig
|
|
|
I have found a way to do this now, but my MailClient is complaining. Is there a way to fix this method from MailClient:
public void sendMessage(String to, String subject, String message)
{
MailItem mess = new MailItem(to, user, subject, message);
server.post(mess);
}
So that it can use my new post method in MailServer?
public void post(String name, MailItem item)
{
if(messages.containsKey(name) == true) // if the key already exists
{
ArrayList list = (ArrayList) messages.get(item); // add the item to the arraylist
}
else
{
ArrayList list = new ArrayList(); // if the key doesn't exist, create a new ArrayList
messages.put(name, list); // add the mailItem to the ArrayList
}
}
The compiler is hanging on the server.post(mess) line as it is expecting (String, MailItem)
|
|
|
hi
can u send me signature or syntax of server.post() method.
|
|
|
|
|
|
|
|