wood burning stoves*
The moose likes Beginning Java and the fly likes updating the date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "updating the date" Watch "updating the date" New topic
Author

updating the date

Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
i have been writing a class for a server of a message board to store the title of a topic, the date of the last post, the message ID, the author of the message and the no.of messages on a topic.
iv written this all fine but im now trying to write a method that should be called to update the date when a new posting occurs. any help is always much apreciated. My code is as follows:

public String getDate(){
return (Date);
}
public void setDate(String latestDate)
{

}
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

You do have a member variable in the class that holds the date, right? Is it called "Date" (that's what you're returning in the getDate method)?

First of all, rename it to "date" instead of "Date". It's not a good idea to name your variables with exactly the same names as classes (in this case, class java.util.Date).

In your set method, you simply assign the value of the parameter (latestDate) to the member variable.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
thanks jesper,
so would this do the job do you think:

public String getDate(){
return (date);
}

public void setDate(String latestDate)
{
latestDate = date;
}
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18520
    
  40

Don't mean to offend you, but a "message board server" may be too ambitious. You might want to consider something easier.

Anyway, assignments are defined the other way around, the variable that you want to assign is on the left.



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
k Oyedeji
Ranch Hand

Joined: Jul 07, 2002
Posts: 96
try



If your get method returns a field which is of type date you will need to change the signature of getDate() as well as illustrated

HTH
Chris Lavery
Ranch Hand

Joined: Nov 30, 2004
Posts: 54
thanks everyone, it did the job perfect
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: updating the date
 
Similar Threads
Help:java.lang.String and java.sql.Date
Comparing two dates
Date Formatting Help
JMS Temporary Topic/Queue
Can't convert String to Date...