I have created an ArrayList that will hold an Email Object.
Each object will hold several strings of data.
The problem I am having is being able to pull the strings of data back out of the ArrayList and display its contents.
This is what is requested of me:
* Hold up to 10 Email objects (DONE)
* Can add an Email object. If the container is full, the add operation does nothing. (DONE)
* Has a method that returns the number of e-mail's stored (DONE)
* Has a method that returns the number of e-mail slots that are still free (DONE)
* Has a method that returns an Email object given its index in the collection (DOH!!!!!)
So by looking at the code, I would have an email get saved in an array... if I call the info back from the ArrayList, I should be able to view the TO,FROM,CC,BCC,SUBJECT, and MESSAGE.
I cannot seem to do the last part, Can anyone help?
~4x4Pirate
public class Email
{
private String to,cc,bcc,subject,message;
public Email(String to,String cc,String bcc,String subject,String message)
{
this.to=to;
this.cc=cc;
this.bcc=bcc;
this.subject=subject;
this.message=message;
}
//--------------------------------------------------
//Requests values from user and returns them
//--------------------------------------------------
public String getTo()
{
return to;
}
public String getCc()
{
return cc;
}
public String getBcc()
{
return bcc;
}
public String getSubject()
{
return subject;
}
public String getMessage()
{
return message;
}
}
---------------------------------------------------------------------------
import java.util.*;
public class EmailList
{
ArrayList email_storage = new ArrayList();
public void EmailAddto (Email stored) //email object called stored
{
if(email_storage.size() <11);
email_storage.add(stored);
}
public int EmailStoredCount()
{
return email_storage.size(); //Returns size of the array list
}
public int EmailSlotFree ()
{
return (10 - email_storage.size()); //determins the number of slots free
}
}
------------------------------------------------------------------------------------------
public class EmailListTest
{
public static void main (String[] args)
{
Email eml = new Email("me@me.com","me","me","me","me");
EmailList EmailArray = new EmailList();
EmailArray.EmailAddto(eml);
System.out.println(EmailArray.EmailSlotFree());
System.out.println(EmailArray.EmailStoredCount());
}
}
---------------------------------------------------------------------------------------------
This post has been edited by 4x4pirate: 21 October 2006 - 11:03 AM

New Topic/Question
Reply




MultiQuote



|