Java School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

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

Join 300,331 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,803 people online right now. Registration is fast and FREE... Join Now!




Calendar program

 

Calendar program, Can you help me please?

drilli

26 May, 2009 - 03:41 AM
Post #1

New D.I.C Head
*

Joined: 26 May, 2009
Posts: 6

Design a calendar program, which takes two inputs: a month (an integer
in range 1..12) and a year (for simplicity, we require an integer of 1900
or larger) and presents as its output the calendar for the month and year
speciŻed. We might use the program to see the calendar for December,
2010:

Su Mo Tu We Th Fr Sa
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31

The application's model will need methods to calculate how many days are
in a given month (within a given year), on what day of the week a given
month, year begins, whether a year is a leap year, etc.


(cool.gif Next, revise the application so that, on demand, the calendar prints a
proper French calendar, that is, the days are presented Monday-Tuesday-
...-Sunday (lundi-mardi-mercredi-jeudi-vendredi-dimanche) with the labels,
lu ma me je ve sa di


User is offlineProfile CardPM
+Quote Post


blackstarzes

RE: Calendar Program

26 May, 2009 - 03:50 AM
Post #2

New D.I.C Head
*

Joined: 25 May, 2009
Posts: 2

Take a look at java.util.Calendar.

If you're not allowed to use that class, you need a static point in time that will give you something to work from (try the epoch - 1 January 1970). Then if you take a look at how the roll() methods work in java.util.Calendar and try to duplicate them in your own class, you might have some luck.
User is offlineProfile CardPM
+Quote Post

rishabhsharma

RE: Calendar Program

26 May, 2009 - 07:04 AM
Post #3

D.I.C Head
Group Icon

Joined: 26 Mar, 2009
Posts: 201



Thanked: 9 times
Dream Kudos: 500
My Contributions
Since it is your first post therefore I am willing to give you source code but from hitherto don't dare to ask free codes, if you want correct codes then firstly show some effort and then we will try to amend your program.

Check out this ............

http://www.dreamincode.net/code/snippet3422.htm

and also

CODE


import java.util.*;
public class CalendarDemo
    {
        public static void CalendarDemo(int Year,int Month,int Date)
            {
                GregorianCalendar a = new GregorianCalendar();
                a.set(Calendar.YEAR,Year);
                a.set(Calendar.MONTH,(Month-1));
                a.set(Calendar.DAY_OF_MONTH,1);
                int weekday = a.get(Calendar.DAY_OF_WEEK);
                int month = a.get(Calendar.MONTH);
                System.out.println("'\n'      YEAR : "+Year);
                switch(month)
                    {
                        case 0:
                        System.out.println();
                        System.out.println("        JANUARY            ");
                        System.out.println();
                        break;
                        case 1:
                        System.out.println();
                        System.out.println("        FEBRUARY           ");
                        System.out.println();
                        break;
                        case 2:
                        System.out.println();
                        System.out.println("         MARCH            ");
                        System.out.println();
                        break;
                        case 3:
                        System.out.println();
                        System.out.println("         APRIL           ");
                        System.out.println();
                        break;
                        case 4:
                        System.out.println();
                        System.out.println("          MAY            ");
                        System.out.println();
                        break;
                        case 5:
                        System.out.println();
                        System.out.println("          JUNE          ");
                        System.out.println();
                        break;
                        case 6:
                        System.out.println();
                        System.out.println("          JULY            ");
                        System.out.println();
                        break;
                        case 7:
                        System.out.println();
                        System.out.println("         AUGUST           ");
                        System.out.println();
                        break;
                        case 8:
                        System.out.println();
                        System.out.println("       SEPTEMBER            ");
                        System.out.println();
                        break;
                        case 9:
                        System.out.println();
                        System.out.println("        OCTOBER           ");
                        System.out.println();
                        break;
                        case 10:
                        System.out.println();
                        System.out.println("        NOVEMBER            ");
                        System.out.println();
                        break;
                        case 11:
                        System.out.println();
                        System.out.println("        DECEMBER           ");
                        System.out.println();
                        break;
                  }
               System.out.println("Sun Mon Tue Wed Thu Fri Sat");
               for(int i=Calendar.SUNDAY;i<weekday;i++)
                {
                    System.out.print("    ");
                }
               do
                    {
                        int day = a.get(Calendar.DAY_OF_MONTH);
                        if(day<10)
                            {
                                System.out.print(" "+day);
                            }
                        else if(day>=10)
                            {
                                System.out.print(day);
                            }
                        if(day==Date)
                            {
                                System.out.print("* ");
                            }
                        else
                            {
                                System.out.print("  ");
                            }
                        if(weekday==Calendar.SATURDAY)
                            {
                                System.out.println();
                            }
                        a.add(Calendar.DAY_OF_MONTH,1);
                        weekday = a.get(Calendar.DAY_OF_WEEK);
                    }
                while(a.get(Calendar.MONTH)==month);
                if(weekday != Calendar.SUNDAY)
                {
                System.out.println();
                }
                System.out.println();
                System.out.println("Note: '*' over any number is your desired number");
            }
        }
                              


User is offlineProfile CardPM
+Quote Post

drilli

RE: Calendar Program

26 May, 2009 - 08:08 AM
Post #4

New D.I.C Head
*

Joined: 26 May, 2009
Posts: 6

Thank you very much rishabhsharma.Now it is all ok with that code

This post has been edited by drilli: 27 May, 2009 - 06:14 AM
User is offlineProfile CardPM
+Quote Post

NeoTifa

RE: Calendar Program

26 May, 2009 - 08:48 AM
Post #5

Yay caek! ZOMG!!!
Group Icon

Joined: 24 Sep, 2008
Posts: 6,292



Thanked: 79 times
Dream Kudos: 150
My Contributions
Why don't you post the code you have?
User is offlineProfile CardPM
+Quote Post

drilli

RE: Calendar Program

26 May, 2009 - 09:38 AM
Post #6

New D.I.C Head
*

Joined: 26 May, 2009
Posts: 6

Thank you very much rishabhsharma.Now it is all ok with that code

This post has been edited by drilli: 27 May, 2009 - 06:11 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 04:21PM

Live Java Help!

Be Social

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

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month