Calender program in JAVA


This is the next level of java programs.But , this is not the basic one. this is some what in depth programs. I’ve posted this for the sake of intermediate leaner.
If you get any doubt on this. please ask us. 
This is the sample Java program for calender, other description about the programs is given as comment,
// CALENDAR CLASS
// All the necessary header files are imported, All the header files are clearly predefined.
import java.io.*;
import java.util.*;
class datetimedetail    // Class Declaration
 {
   Calendar sys = Calendar.getInstance();       // Predefined Calender class declaration and creation of objects.
   GregorianCalendar se = new GregorianCalendar();  // Obj creation for GregorianCalender Function, This is predefined one.
   String mon[]={“JAN”,”FEB”,”MAR”,”APR”,”MAY”,”JUN”,
                 “JUL”,”AUG”,”SEP”,”OCT”,”NOV”,”DEC”};         // Declaring Array for months
  };
   void sysdate()
    {
     System.out.print(“\nTODAY DATE IS = “);
     System.out.print(sys.get(Calendar.DATE));   //  Will get current date
     System.out.print(“/”+mon[sys.get(Calendar.MONTH)]);   // Wil get current month
     System.out.print(“/”+sys.get(Calendar.YEAR));  // will get current year
    }
   void systime()          // This function is used to get the current time, min, sec and other details from system timer.
    {
     System.out.print(“\nNOW TIME IS = “);
     System.out.print(sys.get(Calendar.HOUR));
     System.out.print(“:”+sys.get(Calendar.MINUTE));
     System.out.print(“:”+sys.get(Calendar.SECOND));
     if(sys.get(Calendar.AM_PM)==0)
      System.out.print(“:AM”);
     if(sys.get(Calendar.AM_PM)==1)
      System.out.print(“:PM”);
    }
   void findleap( ) throws IOException
    {
     int l;
     BufferedReader br;
     br = new BufferedReader(new InputStreamReader(System.in));
     System.out.print(“\n ENTER THE YEAR : “);   // Getting year from the user, based on the entered value validation take places
     do
      {
       l = Integer.parseInt(br.readLine());   //Converting sting to integer
       if (0>l)
        {
         System.out.print(“\nYEAR WILL NOT BE IN NEGATIVE”);   //exceptions
         System.out.print(“\nENTER THE CORRECT YEAR : “);
        }
      }
     while(0>l);
     if(se.isLeapYear(l))  // leap year function
       System.out.print(“\nGIVEN YEAR IS LEAP YEAR”);
     else
       System.out.print(“\nGIVEN YEAR IS NOT LEAP YEAR”);
    }
 void setdate() throws IOException  // ioexception is for throws exception
    {
     BufferedReader br;
     br = new BufferedReader(new InputStreamReader(System.in));
     int d,m,y;
     System.out.print(“\nENTER THE DAY : “);  // Getting value from the user for days
     do
      {
       d = Integer.parseInt(br.readLine()); // Same conversion take places
       if ((d < 1) || (d > 31))  // checking for the days 1MIN to 31 MAX
        {
         System.out.print(“\nDAY WILL BE IN 1 TO 31”);
         System.out.print(“\nENTER THE CORRECT DAY : “);
        }
      }
     while((d > 31) || (d < 1));
     sys.set(Calendar.DATE,d);
     System.out.print(“\nENTER THE MONTH : “);  // Month calculation
     do
      {
       m = Integer.parseInt(br.readLine());
       if ((m < 1) || (m > 12))
        {
         System.out.print(“\nMONTH WILL BE IN 1 TO 12”);
         System.out.print(“\nENTER THE CORRECT MONTH : “);
        }
      }
     while((m > 12) || (m < 1));
     sys.set(Calendar.MONTH,(m-1));
     System.out.print(“\nENTER THE YEAR : “);
     do
      {
       y = Integer.parseInt(br.readLine());
       if (0>y)
        {
         System.out.print(“\nYEAR WILL NOT BE IN NEGATIVE”);
         System.out.print(“\nENTER THE CORRECT YEAR : “);
        }
      }
     while(0>y);
     sys.set(Calendar.YEAR,y);
    }
   void settime() throws IOException   // Time calculaion
    {
     BufferedReader br;
     br = new BufferedReader(new InputStreamReader(System.in));
     int h,m;
     System.out.print(“\nENTER THE HOURS : “);
     do
      {
       h = Integer.parseInt(br.readLine());
       if ((h < 1) || (h > 12))
        {
         System.out.print(“\nHOURS WILL BE IN 1 TO 12”);
         System.out.print(“\nENTER THE CORRECT HOUR : “);
        }
      }
     while((h > 12) || (h < 1));
     sys.set(Calendar.HOUR,h);
     System.out.print(“\nENTER THE MINUTES : “);
     do
      {
       m = Integer.parseInt(br.readLine());
       if ((m < 0) || (m > 59 ))
        {
         System.out.print(“\nMINUTES WILL BE IN 0 TO 59”);
         System.out.print(“\nENTER THE CORRECT MINUTE : “);
        }
      }
     while((m > 59) || (m < 0));
     sys.set(Calendar.MINUTE,m);
      System.out.print(“\nENTER AM OR PM : “);
     String ap=br.readLine();
     if ((ap.equals(“am”)) || (ap.equals(“AM”)))
       sys.set(Calendar.AM_PM,0);
     if ((ap.equals(“pm”)) || (ap.equals(“PM”)))
       sys.set(Calendar.AM_PM,1);
    }
 }
 class datetime
  {
   public static void main(String args[]) throws IOException
    {
     String ch;
     datetimedetail da = new datetimedetail();
     BufferedReader br;
     br = new BufferedReader(new InputStreamReader(System.in));
     do
      {  // All the function are given in while loop to call the functions.
       System.out.println(” \n        TIME ZONE “);
       System.out.println(” PRESS ‘D’ FOR TODAY DATE”);
       System.out.println(” PRESS ‘S’ FOR ALTER DATE”);
       System.out.println(” PRESS ‘T’ FOR TIME  NOW”);
       System.out.println(” PRESS ‘A’ FOR ALTER TIME”);
       System.out.println(” PRESS ‘F’ FOR FINDING WHETHER THE YEAR IS LEAP OR NOT”);
       System.out.println(” PRESS ‘E’ EXIT”);
       System.out.print(” ENTER YOUR’S CHOICE : “);
       ch = br.readLine();
       ch=ch.toUpperCase();
       if(ch.equals (“D”))
         da.sysdate();
       else if(ch.equals (“S”))
          da.setdate();
       else if(ch.equals (“T”))
         da.systime();
       else if(ch.equals (“A”))
          da.settime();
       else if(ch.equals (“F”))
          da.findleap();
       else if(ch.equals (“E”))
          System.exit(0);
      }
     while(1<5);
   }
                                                        OUTPUT
        TIME ZONE
 PRESS ‘D’ FOR TODAY DATE
 PRESS ‘S’ FOR ALTER DATE
 PRESS ‘T’ FOR TIME  NOW
 PRESS ‘A’ FOR ALTER TIME
 PRESS ‘F’ FOR FINDING WHETHER THE YEAR IS LEAP OR NOT
 PRESS ‘E’ EXIT
 ENTER YOUR’S CHOICE : d
TODAY DATE IS = 27/SEP/2013
        TIME ZONE
 PRESS ‘D’ FOR TODAY DATE
 PRESS ‘S’ FOR ALTER DATE
 PRESS ‘T’ FOR TIME  NOW
 PRESS ‘A’ FOR ALTER TIME
 PRESS ‘F’ FOR FINDING WHETHER THE YEAR IS LEAP OR NOT
 PRESS ‘E’ EXIT
 ENTER YOUR’S CHOICE : f
 ENTER THE YEAR : 2013
GIVEN YEAR IS NOT LEAP YEAR
        TIME ZONE
 PRESS ‘D’ FOR TODAY DATE
 PRESS ‘S’ FOR ALTER DATE
 PRESS ‘T’ FOR TIME  NOW
 PRESS ‘A’ FOR ALTER TIME
 PRESS ‘F’ FOR FINDING WHETHER THE YEAR IS LEAP OR NOT
 PRESS ‘E’ EXIT
 ENTER YOUR’S CHOICE : a
ENTER THE HOURS : 10
ENTER THE MINUTES : 10
ENTER AM OR PM : am
 TIME ZONE
 PRESS ‘D’ FOR TODAY DATE
 PRESS ‘S’ FOR ALTER DATE
 PRESS ‘T’ FOR TIME  NOW
 PRESS ‘A’ FOR ALTER TIME
 PRESS ‘F’ FOR FINDING WHETHER THE YEAR IS LEAP OR NOT
 PRESS ‘E’ EXIT
 ENTER YOUR’S CHOICE : t
NOW TIME IS = 10:10:0:AM
     TIME ZONE
 PRESS ‘D’ FOR TODAY DATE
 PRESS ‘S’ FOR ALTER DATE
 PRESS ‘T’ FOR TIME  NOW
 PRESS ‘A’ FOR ALTER TIME
 PRESS ‘F’ FOR FINDING WHETHER THE YEAR IS LEAP OR NOT
 PRESS ‘E’ EXIT
 ENTER YOUR’S CHOICE : e
I hope This program will help you, Any queries please comment here.
Advertisements

Tell us Your Suggestion

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s