Hopefully somebody can help. I have successfully created a Java message class to model a standard email message but I am unsure how to proceed with a Mailbox class necessary to store the emails from the Message class.
Message Class
public class Message {
private String recipient;
private String sender;
private String message;
private String body;
public Message(String recipient, String sender){
this.recipient = recipient;
this.sender = sender;
}
public String toString(){
message = "From: " + recipient + "\nTo: " + sender;
return message;
}
public String append(){
body = "\nThis is the body content of your message";
return body;
}
}
Mailbox Class
public class Mailbox {
public void addMessage(Message m)
{
}
public Message getMessage(int i)
{
}
public void removeMessage(int i)
{
}
}
A Vector / ArrayList can hold items / objects. So you can go to your mailbox class and create an ArrayList
ArrayList<Message> messages = new ArrayList<Message>();
Then you can add:
messages.add(new Message(...));
and delete:
messages.delete();
your messages.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.