The Artima Developer Community
Sponsored Link

Java Answers Forum
help me

5 replies on 1 page. Most recent reply: Nov 12, 2003 1:01 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 5 replies on 1 page
bernard

Posts: 6
Nickname: homer
Registered: Nov, 2003

help me Posted: Nov 12, 2003 3:56 AM
Reply to this message Reply
Advertisement
i am so confused. i am trying to get the below code to work but it does'nt . I have two classes 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

import java.util.*;
public class SimpleEmail Email{

public String sender,recipient,subject,content;
public Date dateOfEmail = new Date();

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=new Sender;}

Void setReciepient(String newRecipient){
recipient=new Recipient;}

Void setSubject(String newSubject){
subject=new Subject;}

Void setContent(String NewContent){
content=new Content;
}

}



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");



}
}


David

Posts: 150
Nickname: archangel
Registered: Jul, 2003

Re: help me Posted: Nov 12, 2003 7:31 AM
Reply to this message Reply
Please post compiler messages next time.

Isn't SimpleEmail meant to EXTEND Email?

bernard

Posts: 6
Nickname: homer
Registered: Nov, 2003

Re: help me Posted: Nov 12, 2003 9:22 AM
Reply to this message Reply
Simple email is not meant to extend the email

here are the error messages i get but they don't make sense

--------------------Configuration: JDK version 1.1.8 <Default>--------------------
C:\Program Files\Xinox Software\JCreator LE\MyProjects\SimpleEmail.java:3: Identifier expected.
{ Email{
^
C:\Program Files\Xinox Software\JCreator LE\MyProjects\SimpleEmail.java:27: '}' expected.
}
^
2 errors

Process completed.

Kishori Sharan

Posts: 211
Nickname: kishori
Registered: Feb, 2002

Re: help me Posted: Nov 12, 2003 11:46 AM
Reply to this message Reply
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"); 
 
 
 
}
} 
 

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: help me Posted: Nov 12, 2003 11:52 AM
Reply to this message Reply
The errors make plenty of sense.

public class SimpleEmail Email{ ...


What the heck are you doing? Declaring two classes simultaneously? You said above that it wasn't intended to extend Email; so why is Email there? If you are trying to create a class called SimpleEmail, it should look like this:

public class SimpleEmail
{ 
   ...
}


By the way, when posting code, please use the java tags as described in the Formatting Your Post in the gray box to the right, while writing your post. Your other error might have to do with mismatched braces, but I'm not too excited about the idea of playing parser for this left-aligned code.

Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: help me Posted: Nov 12, 2003 1:01 PM
Reply to this message Reply
> I would suggest you to start with very simple program
> and learn the syntax before you start typing.

This is a good idea. Start small, compile often and you are more likely to encounter one problem at a time. When there are many errors at once, it is much more difficult and complicated.

Languages like Ruby and Python that have an interactive interpreter where you can type in lines of code and have them evaluated live really make learning a breeze. This can't be done in Java, but there are nice IDEs like IDEA and NetBeans that can show you errors as you type (instead of later, when you compile).

Flat View: This topic has 5 replies on 1 page
Topic: Multipart Response Previous Topic   Next Topic Topic:

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use