|
Re: help me
|
Posted: Nov 12, 2003 11:46 AM
|
|
Here is your code that compiles and runs. I think you have just started learning Java. There were many problems in your code. I would suggest you to start with very simple program and learn the syntaxt before you start typing. They were:
1. Java is a case sensistive language. If you write String content; at one place then you cannot refer to it as Content later in your program. Check your original code and you will find such problems with almost all veriables you have used in your program. For example, sometimes you write subject and sometimes Subject. They are not same in Java.
2. Inside all your setXX() methods you have written as:
public void setSubject (String newSubject) {
subject = new subject;
}
There is big difference between new subject and newSubject. "new" is an operator in Java and it is used to create a new object. So your code inside set methods should be as: subject = newSubject;
Here newSubject is the name of argument you are getting.
3. Again case problem. You are using Void as return type for method. It should be void (all lower case).
4. notKnown is a static variable and it must not be declared inside a method. You delcared it inside your main() method in SimpleEmailTest class.
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;
}
}
public class SimpleEmailTest
{
// This must be declared outside main() method
public static final String notKnown = "Unknown";
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
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");
}
}
|
|