Ouputs the Zodiac signs

astrological_sign

The following Java program shows the Zodiac sign corresponding to a given date. This little program can be used to find your Zodiac sign if you input your date of birth.

// Ouputs the Zodiac sign corresponding to a given date.
import java.util.*;
import java.text.DateFormatSymbols;

class TryCalendar {
    public static void main(String[] args) {
        String[] zodiac = {
            "CAPRICORN",
            "AQUARIUS",
            "PISCES",
            "ARIES",
            "TAURUS",
            "GEMINI",
            "CANCER",
            "LEO",
            "VIRGO",
            "LIBRA",
            "SCORPIO",
            "SAGITTARIUS"
        };

        // Dates for the start of each sign period, starting with Aquarius
        GregorianCalendar[] signStartDates = {
            new GregorianCalendar(2000, Calendar.JANUARY, 21),
            new GregorianCalendar(2000, Calendar.FEBRUARY, 20),
            new GregorianCalendar(2000, Calendar.MARCH, 21),
            new GregorianCalendar(2000, Calendar.APRIL, 21),
            new GregorianCalendar(2000, Calendar.MAY, 22),
            new GregorianCalendar(2000, Calendar.JUNE, 22),
            new GregorianCalendar(2000, Calendar.JULY, 24),
            new GregorianCalendar(2000, Calendar.AUGUST, 24),
            new GregorianCalendar(2000, Calendar.SEPTEMBER, 24),
            new GregorianCalendar(2000, Calendar.OCTOBER, 24),
            new GregorianCalendar(2000, Calendar.NOVEMBER, 23),
            new GregorianCalendar(2000, Calendar.DECEMBER, 22)
        };
// Get the calendar for a birthday
        GregorianCalendar birthday = getDate(); 

        String yourSign = zodiac[0]; // Set CAPRICORN as default
        for (int i = 0; i0 && month < 13 && 
        day > 0 && day <= monthDays[month - 1])
            return new GregorianCalendar(2000, month - 1, day);
        System.out.println("Invalid date entered. Try again.");
    }
    System.out.println("Five invalid dates entered. Sorry - no more tries...");
    System.exit(1);
    return null;
}

private static int[] monthDays = {
    31,
    29,
    31,
    30,
    31,
    30,
    31,
    31,
    30,
    31,
    30,
    31
};
private static FormattedInput in = new FormattedInput();
}

//******************************************
//FormattedInput.java
//******************************************
import java.io.*;

public class FormattedInput implements Serializable {
    public String stringRead() {
        try {
            for (int i = 0; i < 5; i++) {
                int tokenType = tokenizer.nextToken();
                if (tokenType == tokenizer.TT_WORD || tokenType == '\"')
                    return tokenizer.sval;
                else if (tokenType == '!')
                    return "!";
                else {
                    System.out.println("Incorrect input. 
                    Re-enter a string between double quotes");
                    continue;
                }
            }
            System.out.println("Five failures reading a string" + 
            " - program terminated");
            System.exit(1);
            return null;
        } catch (IOException e) {
            System.out.println(e);
            System.exit(1);
            return null;
        }
    }

    public int intRead() {
        try {
            for (int i = 0; i < 5; i++) {
                if (tokenizer.nextToken() == tokenizer.TT_NUMBER && 
                tokenizer.nval == (double)((long) tokenizer.nval))
                    return (int) tokenizer.nval;
                else {
                    System.out.println("Incorrect input: " + 
                    tokenizer.sval + 
                    " Re-enter an integer");
                    continue;
                }
            }
            System.out.println("Five failures reading an int value" + 
            " - program terminated");

            System.exit(1);
            return 0;
        } catch (IOException e) {
            System.out.println(e);
            System.exit(1);
            return 0;
        }
    }
    private StreamTokenizer tokenizer = new 
    StreamTokenizer(new InputStreamReader(System.in));
}
M. Saqib: Saqib is Master-level Senior Software Engineer with over 14 years of experience in designing and developing large-scale software and web applications. He has more than eight years experience of leading software development teams. Saqib provides consultancy to develop software systems and web services for Fortune 500 companies. He has hands-on experience in C/C++ Java, JavaScript, PHP and .NET Technologies. Saqib owns and write contents on mycplus.com since 2004.
Related Post