Welcome to Dream.In.Code
Become a Java Expert!

Join 150,195 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,012 people online right now. Registration is fast and FREE... Join Now!




Calendar util stuff

 
Reply to this topicStart new topic

Calendar util stuff, using the calendar utility

lucindaG
27 Sep, 2008 - 03:15 PM
Post #1

New D.I.C Head
*

Joined: 27 Sep, 2008
Posts: 1

Hello everyone, I'm just learning and trying to do a homework problem. I pasted my code in; i keep getting 3 errors that I can't seem to fix no matter what i do. crazy.gif blink.gif I pasted those below my program. Help! biggrin.gif

CODE
import java.util.GregorianCalendar;
import java.util.Calendar;

public class Lucyscalendar{
    public static void main (String args[])
   {

        //get today's date by creating a new calendar
        GregorianCalendar cal = new GregorianCalendar();

        //gets the date 100 days from today
        String day100 = cal.add(Calendar.DAY_OF_MONTH, 100);

         // I want to create a new calendar based on my birthday
        GregorianCalendar LucyBirthday = new GregorianCalendar(1988, Calendar.September, 18);

        //gives me weekday of my birdthday
        int lucyDay =LucyBirthday.get(Calendar.DAY_OF_WEEK);

        //i want to get 1000 days from my birthday
        int lucyGrand = LucyBirthday.add(Calendar.DAY_OF_MONTH, 10000);

        int dayofMonth= cal.get(Calendar.DAY_OF_MONTH);
        int  month= cal.get(Calendar.MONTH);
        int  year= cal.get(Calendar.YEAR);
        int weekday = cal.get(Calendar.DAY_OF_WEEK);

        System.out.println ("A hundred days from today will be " +day100+ ".");
        System.out.println( "My birdthday was on a " +lucyDay);
        System.out.println("A thousand days from my birthday would be " +lucyGrand+ ".");
    }
}



And these are the errors messages:
CODE
Lucyscalendar.java:14: cannot find symbol
symbol  : variable September
location: class java.util.Calendar
        GregorianCalendar LucyBirthday = new GregorianCalendar(1988, Calendar.September, 18);
                                                                             ^
Lucyscalendar.java:16: incompatible types
found   : void
required: java.lang.String
        String day100 = cal.add(Calendar.DAY_OF_MONTH, 100);
                               ^
Lucyscalendar.java:22: incompatible types
found   : void
required: int
        int lucyGrand = LucyBirthday.add(Calendar.DAY_OF_MONTH, 10000);
                                        ^

User is offlineProfile CardPM
+Quote Post

pbl
RE: Calendar Util Stuff
27 Sep, 2008 - 03:51 PM
Post #2

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
CODE

import java.util.Date;
import java.util.GregorianCalendar;
import java.util.Calendar;

public class Lucyscalendar{
    public static void main (String args[])
   {

        //get today's date by creating a new calendar
        GregorianCalendar cal = new GregorianCalendar();

        //gets the date 100 days from today
        // the method add(...) is a void it does not return a String
        // String day100 = cal.add(Calendar.DAY_OF_MONTH, 100);
        // you will have to proceed in 2 steps
        cal.add(Calendar.DAY_OF_MONTH, 100);
        String day100 = cal.getTime().toString();
        
         // I want to create a new calendar based on my birthday
         // Java constants are usually in UPPERCASE
        // GregorianCalendar LucyBirthday = new GregorianCalendar(1988, Calendar.September, 18);
        GregorianCalendar LucyBirthday = new GregorianCalendar(1988, Calendar.SEPTEMBER, 18);

        //gives me weekday of my birdthday
        int lucyDay = LucyBirthday.get(Calendar.DAY_OF_WEEK);

        //i want to get 1000 days from my birthday
        // add() again does not return nothing
        // int lucyGrand = LucyBirthday.add(Calendar.DAY_OF_MONTH, 10000);
        LucyBirthday.add(Calendar.DAY_OF_MONTH, 10000);
        String lucyGrand = LucyBirthday.getTime().toString();

        int dayofMonth= cal.get(Calendar.DAY_OF_MONTH);
        int  month= cal.get(Calendar.MONTH);
        int  year= cal.get(Calendar.YEAR);
        int weekday = cal.get(Calendar.DAY_OF_WEEK);

        System.out.println ("A hundred days from today will be " +day100+ ".");
        System.out.println( "My birdthday was on a " +lucyDay);
        System.out.println("A thousand days from my birthday would be " +lucyGrand+ ".");
    }
}



And happy birthday 9 days late smile.gif
User is offlineProfile CardPM
+Quote Post

nikkitta320
RE: Calendar Util Stuff
29 Sep, 2008 - 04:53 PM
Post #3

New D.I.C Head
*

Joined: 29 Sep, 2008
Posts: 2

i had the same problem as lucy, but the output for my code is supposed to print the dates and weekdays as numbers. i have tried everything i could from looking at the calendar class and gregorian calendar class. is there anyway to get a ore simple output than cal.getTime?

this is what i have so far, i have commented out alot of it to work on certain parts. getting pretty frustrated

CODE

import java.util.Calendar;
import java.util.GregorianCalendar;


public class Project2_1
{
    public static void main (String [] args)
    {
        //Create a new calendar to get today's date
        GregorianCalendar cal = new GregorianCalendar();

        //adds a 100 days to today's date
        cal.add(Calendar.DAY_OF_MONTH,100);

        
        single String day100 = cal.getMinimumTim() .toString();

        cal.add(Calendar.DAY_OF_WEEK,100);

        //Calendar.DAY_OF_WEEK

        //int Week100 = GregorianCalendar.get (Calendar.DAY_OF_WEEK, 100);

        //String week100 = cal.getTimeMinimum().toString ();

        //protected void computeFields;
        //int week100;r

        //String strweek100;

        //Create a new calendar based on my birthday
        GregorianCalendar NikkisBirthday = new GregorianCalendar (1982, Calendar.MARCH, 20);

        //Gets the weekday of my birthday
        int NikkiDay = NikkisBirthday.get (Calendar.DAY_OF_WEEK);

        //Adds 10,000 days from my birthday
        NikkisBirthday.add (Calendar.DAY_OF_MONTH,10000);

        //String nikkiBDayThou = NikkisBirthday.getMinimumTime().toString();

        int dayOfMonth = cal.get (Calendar.DAY_OF_MONTH);

        int month = cal.get(Calendar.MONTH);

        int year = cal.get(Calendar.YEAR);

        int weekday = cal.get(Calendar.DAY_OF_WEEK);

        //Prints out what a 100 days from today would be
        System.out.println ("The day that is 100 days from today is: " + day100);

        //Prints out what 100 weekdays from today would be
        //System.out.println ("The weekday that is 100 days from today is: " + week100);

        //Prints out the weekday of my birthday
        System.out.println ("The weekday of my birthday is: " + NikkiDay);

        //Prints out what 10,000 days from my birthday would be
        System.out.println ("The date that is 10,000 days from my birthday is: " + nikkiBDayThou);


    }
}

Edited to add the [ code] tags
code.gif

This post has been edited by pbl: 29 Sep, 2008 - 05:00 PM
User is offlineProfile CardPM
+Quote Post

pbl
RE: Calendar Util Stuff
29 Sep, 2008 - 05:03 PM
Post #4

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
CODE

      
        single String day100 = cal.getMinimumTim() .toString();



"single" is not a Java word. What do you try to achieve ?

getMinimumTim() is not a method of Calendar.. where did you got it ?

User is offlineProfile CardPM
+Quote Post

nikkitta320
RE: Calendar Util Stuff
29 Sep, 2008 - 05:09 PM
Post #5

New D.I.C Head
*

Joined: 29 Sep, 2008
Posts: 2

grasping at straws, trying to find something that works


i need an output that looks something like:

"The date that is 100 days from today is: 20"
rather than "Mar 12"
User is offlineProfile CardPM
+Quote Post

pbl
RE: Calendar Util Stuff
29 Sep, 2008 - 06:42 PM
Post #6

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
QUOTE(nikkitta320 @ 29 Sep, 2008 - 06:09 PM) *

"The date that is 100 days from today is: 20"
rather than "Mar 12"


And what is supposed to be 20 ? Surely not the day of the month as it is the 12th

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 04:35AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month