1 Replies - 8096 Views - Last Post: 21 October 2006 - 12:19 PM Rate Topic: -----

#1 4x4pirate  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 54
  • Joined: 18-October 06

Pulling data out of an ArrayList in Java and displaying the content

Posted 21 October 2006 - 10:51 AM

3 Classes.. Email, EmailList and EmailList Test..

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


Is This A Good Question/Topic? 0
  • +

Replies To: Pulling data out of an ArrayList in Java and displaying the content

#2 dragonlady  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 57
  • Joined: 07-August 05

Re: Pulling data out of an ArrayList in Java and displaying the content

Posted 21 October 2006 - 12:19 PM

Have you got any code showing an attempt to do that last part? What I'm really asking is, do you have a method already where you pass as an argument the index of the email you want, and it just doesn't work?

If you're not even sure where to start for the last part, I'd recommend you look at this link: http://java.sun.com/.../ArrayList.html

Scroll down and have a look at the Method Summary. I don't want to give away the answer, but I believe if you check out the class's methods you'll be able to finish up the last part very quickly :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1