954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Help Java novice

Hi All,

I am a total java novice and i am having a real problem running the following code:

import java.util.*;
 
public class Methods
{
public static void main( String [] args)
{
 
Date independenceDay = new Date ( 7, 4, 1776 );
int independenceMonth = independenceDay.getMonth();
System.out.println("Independence day is in month " + independenceMonth);
 
 
Date graduationDate = new Date (5, 15, 2008);
System.out.println("The current day for graduation is " + graduationDate.getDay() );
 
graduationDate.setDay(12);
System.out.println( "The revised day for graduation is " + graduationDate.getDay() );
}
}

This is actually from a book i am working through and if it isn't working i was wondering if there was something wrong with the code or my pc.

The error message reads:

1 error found:
File: C:\Documents and Settings\Steven\Desktop\Methods.java [line: 16]
Error: cannot find symbol
symbol : method setDay(int)
location: class java.util.Date


Please help

Thanks
Sarah
x

sarahavickers
Newbie Poster
2 posts since Oct 2006
Reputation Points: 10
Solved Threads: 0
 

First of all, many of the methods in the Date class is depreciated. They are still implemented, but the Calendar class fills the same niche better.

As for your actual problem, you'd be after the setDate(int) method.

Check you the Java API if you haven't already.

DavidRyan
Posting Whiz in Training
229 posts since Jul 2006
Reputation Points: 22
Solved Threads: 11
 

There is no setDay() method in the Date Class, this mean your book must be old and you will get more similar problems...
Follow the link which David give it to you, in packages find java.util, then bellow find Date and read trough
I use now Deitel&Deitel JAVA How to Program 6th edition

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You