Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Java Date Example 
 

In this section we will be getting the astrological sign according to the inserted birth date by the user. To get the astrological sign first we require to have a date object which will be providing the inserted date by the user.

 

Java Date Examples

                         

Getting astrological sign according to birth date

In this section we will be getting the astrological sign according to the inserted birth date by the user. To get the astrological sign first we require to have a date object which will be providing the inserted date by the user. 

Suppose in our example we have initialized the date, which is to be checked with 19 December 1986. 

Date date = new Date(86,12,19);

Another date object check is being used in our program for providing the astrological sign by comparing it with another date object. Here is the following list of date ranges according to which we are giving astrological sign. This list is as follows:

  Date Range   Astrological Sign
December 22 - January 19 Capricorn
January 20 - February 18 Aquarius
February 19 - March 20 Pisces
March 21 - April 19 Aries
April 20 - May 20 Taurus
May 21 - June 20 Gemini
June 21 - July 22  Cancer
July 23 - August 22  Leo
August 23 - September 22  Virgo
September 23 - October 22  Libra
October 23 -November 21  Scorpio
November 22 - December 21  Sagittarius

Here is the full example code of AstrologicalSign.java as follows:

AstrologicalSign.java

import java.util.Date;

public class AstrologicalSign
{
  public static void main(String args[]){
    int year;
    Date date = new Date(86,12,19);
    Date check;
    String astrologicalSign=new String("");
    year = date.getYear();
    while (true) {

      // December 22 - Januray 19 --> Capricorn
      check = new Date(year,1,20);
      if(date.before(check)) {
        astrologicalSign = new String("Capricorn");
        break;
      }
      
      // Januray 20 - February 18 --> Aquarius
      check =  new Date(year,2,19);
      if(date.before(check)) {
        astrologicalSign = new String("Aquarius");
        break;
      }
      
      // February 19 - March 20  --> Pisces
      check =new Date(year,3,21);
      if(date.before(check)) {
        astrologicalSign = new String("Pisces");
        break;
      }
      
      // March 21 - April 19  --> Aries
      check =  new Date(year,4,20);
      if(date.before(check)) {
        astrologicalSign = new String("Aries");
        break;
      }

      // April 20 - May 20  --> Taurus
      check =  new Date(year,5,21);
      if(date.before(check)) {
        astrologicalSign = new String("Taurus");
        break;
      }
      
      // May 21 - June 20 --> Gemini
      check =  new Date(year,6,21);
      if(date.before(check)) {
        astrologicalSign = new String("Gemini");
        break;
      }
      
      // June 21 - July 22  --> Cancer
      check =  new Date(year,7,23);
      if(date.before(check)) {
        astrologicalSign = new String("Cancer");
        break;
      }
      
      // July 23 - August 22  --> Leo
      check =  new Date(year,8,23);
      if(date.before(check)) {
        astrologicalSign = new String("Leo");
        break;
      }

      // August 23 - September 22  --> Virgo
      check =  new Date(year,9,23);
      if(date.before(check)) {
        astrologicalSign = new String("Virgo");
        break;
      }
      
      // September 23 - October 22 --> Libra
      check =  new Date(year,10,23);
      if(date.before(check)) {
        astrologicalSign = new String("Libra");
        break;
      }
      
      //October 23 -November 21  --> Scorpio
      check =  new Date(year,11,22);
      if(date.before(check)) {
        astrologicalSign = new String("Scorpio");
        break;
      }
      
      // November 22 - December 21  --> Sagittarius
      check =  new Date(year,12,22);
      if(date.before(check)) {
        astrologicalSign = new String("Sagittarius");
        break;
      }
    }
    System.out.println("Your astrological sign is =>> "+astrologicalSign);
  }
}

Output:

To get the astrological sign accordingly first provide the birth date.

C:\DateExample>javac AstrologicalSign.java

C:\DateExample>java AstrologicalSign
Your astrological sign is =>> Capricorn

Download Source Code

                         

» View all related tutorials
Related Tags: java c class time calendar method arguments field this ai package ie example add with mount program ram exam span

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.