java help me


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: java help me

  1. #1
    Join Date
    Nov 2003
    Posts
    13

    java help me

    i am so confused. i am trying to get the below code to work but it does'nt . I have two classes in two different .java files one called simpleemail and 1 called simpleemailtester. the simpleemailshould transfer the values of the input to the corresponding class attributes. but it's not working here is the code below can n e 1 help
    Code:
    public class SimpleEmailTest 
    
    {
    	
    	public static void main( String[] args ) 
    	
    	{
    		 SimpleEmail Email;	// email object to test.
    		 String whoFrom;		// sender
    		 String whoTo;		// recipient
    		 String subject;		// subject matter
    		 String content;		// text content of email
    		
    		public static final String notKnown = "Unknown";
    
    		email = new SimpleEmail(notKnown, notKnown, notKnown, notKnown);
    
    		System.out.println( "SimpleEmail: " + 
                    "\n    From: " + email.getSender() + 
                    "\n      To: " + email.getRecipient() + 
                    "\n Subject: " + email.getSubject() + 
                    "\n    Date: " +  
                      email.getDate().toString() + 
                    "\n Message: \n" + email.getContent() + "\n"); 
    
    
    		email.setSender( "Suresh Testsender");
    		email.setRecipient( "Suresh1 Receiver");
    		email.setSubject( "How are you today?");
    		email.setContent( "I just wrote an email class!");
    
    		System.out.println( "SimpleEmail: " + 
            "\n    From: " + email.getSender() + 
            "\n      To: " + email.getRecipient() + 
            "\n Subject: " + email.getSubject() + 
            "\n    Date: " +  
            email.getDate().toString() + 
            "\n Message: \n" + email.getContent() + "\n"); 
    
    
    
    	}
    }

    Code:
    import java.util.*;
    
     class SimpleEmail 
    { 
    	public String sender,recipient,subject,content; 
    		public Date dateOfEmail = new Date(); 	
    			public SimpleEmail ( String sender, String recipient, String subject, String content)
    			 {		
    			  this.sender = sender;		
    			  this.recipient = recipient;		
    			  this.subject = subject; 		
    			  this.content = content;	
    			  }	
    			  String getSender(){return sender;
    			  }	
    			  String getRecipient(){return recipient;}
    			  	String getSubject(){return subject;}	
    			  		String getContent(){return content;}	
    	Date getDate(){return dateOfEmail;}	
    	void setSender(String newSender){	
    			  		sender=newSender;	}	
    	void setRecipient(String newRecipient){		recipient=newRecipient;	}
    	void setSubject(String newSubject){		subject=newSubject;	}
    	void setContent(String NewContent){		content=NewContent;	}}
    simple email compiles just fine but here are the errors i get when compiling simpleemailtest. can n e 1 help
    Code:
    --------------------Configuration: JDK version 1.1.8 <Default>--------------------
    C:\Program Files\Xinox Software\JCreator LE\MyProjects\SimpleEmailTest.java:12: '}' expected.
    		 String content;		// text content of email
    		                ^
    C:\Program Files\Xinox Software\JCreator LE\MyProjects\SimpleEmailTest.java:14: Statement expected.
    		public static final String notKnown = "Unknown";
    		^
    C:\Program Files\Xinox Software\JCreator LE\MyProjects\SimpleEmailTest.java:16: Identifier expected.
    		email = new SimpleEmail(notKnown, notKnown, notKnown, notKnown);
    		     ^
    3 errors
    
    Process completed.

    [ArchAngel added CODE tags]

  2. #2
    Join Date
    Nov 2003
    Posts
    5
    Just two small things should fix you up.

    First, in your main, you've got the variable "SimpleEmail Email" but throughout your code you've changed it to "email". You're using a small "e" instead of a capital.

    Second, you've got the string notKnown declared as "public static final". The only modifier you would want here is final, not public or static.

    It ran fine for me once I fixed these mistakes.

    Good luck!

    WN

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center