Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

vector help

  Asked By: Jasmine    Date: Nov 05    Category: Java    Views: 885
  

Can some one help me i have written a very simple set of classes.
the first class simple email takes values that are hard coded in to
simpleemailtester and then stores them and in some cases validates
them. This part works fine.

But then i have created a class called email handler which sets up a
vector to store multiple emails. What i am now trying to do is
create a emailhandlertest class which intialises the vector and then
stores a few hard coded books in to it. Below is all the code of
what i have done so far. but i just can't get it to work and i can't
figure out why. Please help me.





import java.util.*;
class SimpleEmail {

private String sender;
private String sendermail;
private String recipient;
private String recipientmail;

private String subject;
private String content;

private String messageID; // unique id for email
private String returnPath; // a return Email if fails
private String org; //company name
private String mime; //version if encoded
private String mailer; //name of mail client used
private String contentType; //text/plain charset= US-ascii

private Date dateOfEmail;

public SimpleEmail(String s,String sm, String r,String rm,String
mi,String rp,String o, String mm, String ml, String ct,String t,
String c, Date d) {

sender = s;
sendermail = sm;
recipient = r;
recipientmail = rm;

messageID = mi;
returnPath = rp;
org = o;
mime = mm;
mailer = ml;
contentType = ct;


subject = t;
content= c;

dateOfEmail = d;
}

public void setSender(String s) {
sender = s;
if ( sender == " ")
sender = "unknown";
}
public String getSender() {
return sender;
}



public void setSenderMail(String sm) {
sendermail = sm;





if ( sendermail == " ")
sendermail = "unknown";
}
public String getSenderMail() {
if( isAddressValid ( sendermail ) ) {
sendermail = " Alert ----> Invalid email address";
}

return sendermail;
}



public void setRecipient(String r) {
recipient = r;
if ( recipient == " ")
recipient = "unknown";
}
public String getRecipient() {


return recipient;
}



public void setRecipientMail(String rm) {
recipientmail = rm;
if ( recipient == " ")
recipientmail = "unknown";
}
public String getRecipientMail() {
if( isAddressValid ( recipientmail ) ) {
recipientmail = " Alert ----> Invalid email address";
}


return recipientmail;
}



public void setMessageId(String mi) {
messageID = mi;
if ( messageID == " ")
messageID = "unknown";
}
public String getMessageId() {
return messageID;
}




public void setReturnPath(String rp) {
returnPath = rp;
if ( returnPath == " ")
returnPath = "unknown";
}
public String getReturnPath() {
return returnPath;
}



public void setOrg(String o) {
org = o;
if ( org == " ")
org = "unknown";
}
public String getOrg() {
return org;
}



public void setMime(String mm) {
mime = mm;
if ( mime == " ")
mime = "unknown";
}
public String getMime() {
return mime;
}



public void setMailer(String ml) {
mailer = ml;
if ( mailer == " ")
mailer = "unknown";
}
public String getMailer() {
return mailer;
}



public void setcontentType(String ct) {
contentType = ct;
if ( contentType == " ")
contentType = "unknown";
}
public String getcontentType() {
return contentType;
}



public void setSubject(String t) {
subject = t;
if ( subject == " ")
subject = "unknown";

}
public String getSubject() {
return subject;
}

public void setContent(String c) {
content = c;
if ( content == " ")
content = "unknown";
}
public String getContent() {
return content;
}

public void setDate(Date d) {
dateOfEmail = d;
}
public Date getDate() {
return dateOfEmail;
}



boolean isAddressValid(String address){
int opPos=address.indexOf("@");
if(opPos==-1){//no @
return(true);
}
if(address.indexOf("@",opPos)!=-1){//more then one @
return(true);
}

if(address.indexOf(".")<opPos){//checks that there are no
dots //before the @
return(true);
}
if(address.indexOf(".",opPos)==-1){//checks that there is at least
one dot after the @
return(true);

}


return(false);//if none of the flags rose up it means that the email
is valid



}
}


import java.util.*;
public class SimpleEmailTest
{


public static final String notKnown = "Unknown";
public static void main( String[] args )
{
SimpleEmail email; // email object to test.
String whoFromName; // sender
String fromMail;// sender email address
String whoToName; // recipient
String toMail;// recipients email address
String messageID; // unique id for email
String returnPath; // a return Email if fails
String org; //company name
String mime; //version if encoded
String mailer; //name of mail client used
String contentType; //text/plain charset= US-ascii
String subject; // subject matter
String content; // text content of email

Date recieved = new Date();

email = new SimpleEmail( notKnown, notKnown, notKnown, notKnown,
notKnown, notKnown, notKnown, notKnown, notKnown, notKnown,
notKnown, notKnown, recieved );




email.setSender( "Suresh" );
email.setSenderMail(" sureshdutt@...");

email.setRecipient( "Sheena Receiver" );
email.setRecipientMail(" SheenaReciever@...");

email.setMessageId("12212.4224.3443.3");
email.setReturnPath("admin@...");
email.setOrg("Dutts Independant Traders(DITS)");
email.setMime("Verseion 1");
email.setMailer("outlook express");
email.setcontentType("text charset= US-ASCII");


email.setSubject( "How are you today?" );
email.setContent( "I just wrote an email class!" );

System.out.println( "SimpleEmail: " +
"\n From: " + email.getSender() + email.getSenderMail() +
"\n To: " + email.getRecipient() + email.getRecipientMail() +
"\n Subject: " + email.getSubject() +
"\n Message ID: " + email.getMessageId() +
"\n Return Path: " + email.getReturnPath() +
"\n Organisation: " + email.getOrg() +
"\n MIME: " + email.getMime() +
"\n Mailer: " + email.getMailer() +
"\n Content Type: " + email.getcontentType() +
"\n Date: " +
email.getDate().toString() +
"\n Message: " + email.getContent() + "\n");



}
}





import java.util.*;
public class EmailHandler {

private Vector emails;

public Email() {
emails = new Vector();
}
public Email(int size) {
emails = new Vector(size);
}

public void Store(email e) {
emails.addElement(e);
}

}


import java.util.*;
public class EmailHandlerTest {

public static void main (String[] args){

Date today = new Date();

SimpleEmail e1, e2, e3, e4;



Email email = new Email(20);


e1 = new SimpleEmail("Suresh", " sureshdutt@...", "Sheena
Receiver","
SheenaReciever@...","12212.4224.3443.3","admin@...","
Dutts Independant Traders(DITS)","Verseion 1","How are you
today?","I just wrote an email class!", today);


email.addEmail(e1);





}


}



here are the errors i get when i try to compile th emailhandlertest
class

--------------------Configuration: JDK version 1.1.8 <Default>-------
-------------
C:\Program Files\Xinox Software\JCreator
LE\MyProjects\EmailHandlerTest.java:12: Class Email not found in
type declaration.
Email email = new Email(20);
^
C:\Program Files\Xinox Software\JCreator
LE\MyProjects\EmailHandlerTest.java:12: Class Email not found in
type declaration.
Email email = new Email(20);
^
2 errors

Process completed.

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Marc Anderson     Answered On: Nov 05

if ( anything == " ") isn't going to be much use to you
try replacing those sort of if statements with if(isBlank(anything))
where isBlank is defined as below

private boolean isBlank(String str)
{
if(str==null) return  true;
if(str.trim().equals("")) return true;
return false;
}

what you are doing in your code  is comparing the handle of the respective
strings not the content
you could do something like if(" ".equals(anything)) if you only wanted to test
for
the single space character (but I don't think that is what you really want.

 
Didn't find what you were looking for? Find more on vector help Or get search suggestion and latest updates.




Tagged: