?
2012-09-06 12:03:17 UTC
//Instructions..
What are the requirements on the classes?
1. Each desktop will have its own message store.
2. The dekstopMessageHolder will consist of recent and history messages and the
desktopId.
3. As soon as the recent message list has more than 10 entries the oldest message is
removed and transferred to the history message list.
4. The history messages list can only hold 1000 messages at which point the oldest
message is discarded.
How its supposed to work:
1. The DekstopMessageHandler class is instantiated.
2. A message is send to the DesktopMessageHandler to store using its
storeMessage(String message,int desktopId) method.
3. The MessageHandler should check its desktopMessageData list to see if it has a
object with the correct desktop ID. If so store the message in recent and handle
the overflows. Else create a new store object in the list and store the message in
recent.
4. Messages are retrieved as a complete list of messages via the List
getRecent/HistoryMessage(int dekstopId) method.
//How far I got..
//========================MessageHandl… class
import java.util.list;
class MessageHandler{
//Variables
String message;
int desktopId;
//Constructor
public storeMessage(String message, int desktopId){
this.message = message;
this.desktopId = desktopId;
}
public String getRecentMessages(int desktopId){
return recentMessages[desktopId]; //??? Not sure if this is right
}
}
//========================DesktopMessa…
import java.uitl.List;
import java.util.Scanner;
import java.uitl.Random;
class DesktopMessageHolder{
public static void main(String[]args){
List recentMessages = new LinkedList();
recentMessages = new ArrayList();
List historyMessages = new LinkedList();
historyMessages = new ArrayList();
int desktopId = 1;
MessageHandler myMessageHandler = new MessageHandler();
for(int x = 0; x++; x < 1000){
desktopId = random(10);
recentMessages[desktopId]; //??? Not sure if this is right either
myMessageHandler.storeMessage("Msg No: " + x.toString(), desktopId);
}
System.out.print(myMessageHandler.getRecentMessages(desktopId).toString());
myMessageHandler = new MessageHandler();
desktopId = 1;
for(int i = 0; i++; i < 1001){
myMessageHandler.storeMessage("Message number:" + i.toString(), desktopId);
}
}
}
Please help me.. :I