
/**
    AssignOne.java
    author:  Robert Kingston
    version:  3 - first release
	Date:	01/04/05
    This is a simple astrology program for the PPS assignment one.
	Stage Reached: Stage 3
*/

import pps.Keyboard;

public class AssigOne
{

    public static void main(String[ ] args) 
    {
	
	//Declare Variables
	final String FINSTAR = "aries"; //This variable is the starsign at time of writting
	final String FINSTARCAPITAL = "Aries"; //This variable is the starsign at time of writting with a capital
	final String FINSTARUPPER = "ARIES"; //This variable is the starsign at time of writting with all capitals
	final boolean DEBUG = false; //This can be turned on to display the debugging messages
	int yob; //yob is for storing 'Year of Birth'
	int counter = 0; //this is for stage two's looping to reask the questions
	char gender; //gender is for storing m/f for male or female. 
	char continueMarker; //this is for stage two's looping. This is to break out of the loop
	boolean reasonable; //this is for stage threes reasonable date test
	String starsign, addressterm, message; //starsign is for the user-entered starsign. addressterm will be either madam/sir. message will be the final horoscope.
	
	
	//Welcome Message.
	System.out.println("\n\n--------------------------------------\nWelcome to JawaPro's Astrology program\n--------------------------------------\n");
	
	do
	{
	
		//Enter year of birth
		System.out.println("\nPlease enter the year of your birth."); 
		
		//this loop is to determine that the year of birth is reasonable (between 1900 and 2005) 
		do
		{
			yob = Keyboard.readInt();
			if (DEBUG)
			{
				System.out.println("Debugging Message: User entered: " + yob);
			} //close debug
			// if yob is between the daes (incusive) then it is reasonable
			if ((yob >= 1900) &&  (yob <= 2005))
			{
				if (DEBUG)
				{
					System.out.println("Debugging Message: The year of Birth is reasonable");
				} //close debug
				reasonable = true;
			} //close if
			else
			{
				//if it is not reasonable you will reloop. Print out a message to explain whats going on
				if (DEBUG)
				{
					System.out.println("Debugging Message: User entered an unreasonable Year of Birth");
				} //close debug
				reasonable = false;
				System.out.println("Liar! - what's your REAL birthyear?");
			} 
    	}while (reasonable == false); //Close do loop
	
		
	
		//Enter Gender
		System.out.println("\nPlease enter your gender (m/f).");  
		gender = Keyboard.readChar(); 
		
		if (DEBUG)
		{
			System.out.println("Debugging Message: User entered: " + gender);
		} //close debug
		
		//Work out addressterm (Sir or Madam) depending on Male or Female
		if (gender == 'm' || gender == 'M')
		{
			addressterm =  new String("Sir");
		} //close if
		else
		{
			addressterm =  new String("Madam");;
		} //close else
	
		if (DEBUG)
		{
			System.out.println("Debugging Message: Term of Address: " + addressterm);
		} //close debug
		
		//Enter Starsign
		System.out.println("\nPlease enter your starsign.");  
		starsign = Keyboard.readString(); 
		
		if (DEBUG)
		{
			System.out.println("Debugging Message: User entered: " + starsign);
		} //close debug
		
				
		//Check if starsign is current
		if (starsign.equals(FINSTAR)||starsign.equals(FINSTARCAPITAL)||starsign.equals(FINSTARUPPER))
		{
			if (DEBUG)
			{
				System.out.println("Debugging Message: Starsign is Current.");
			} //close debug
			message = ", this birthday will be a good one.";
		} //close if
		else //Now for everthing else that isnt the same as current starsign
		{
			//Is it a leap year? And is the final letter of the starsign a 's' or 'S'?
			if (((yob % 4) == 0) && (starsign.charAt(starsign.length() - 1)=='s') || ((yob % 4) == 0) && (starsign.charAt(starsign.length() - 1)=='S'))
			{
				if (DEBUG)
				{
					System.out.println("Debugging Message: Starsign ends with S and it is a leap year.");
				} //close debug
				message = ", you are destined for greatness.";
			} //close if
			else
			{
				if (DEBUG)
				{ 
					System.out.println("Debugging Message: Starsign is not Current And does not end with 'S' OR is not a leap-year.");
				} //close debug
				message = ", You are unlucky buddy!";
			} //Close else (leapyear and S)
		
		} //close else (starsign current)
	
		//print the final message. Man alive I miss the simple echo ""; command from php...
		System.out.println("\n\n\n" + addressterm + message + "\n------------------------");
	
	//ask if you would like to continue
	System.out.println("Would you like to try another horoscope? (y/n)");
	continueMarker = Keyboard.readChar();
	//increase counter. This keeps track of how many times you have done the loop - usefully to determine if you are going 'loopy'
	counter++;
	if (DEBUG)
	{ 
		System.out.println("Debugging Message: You have currently viewed: " + counter + " horoscopes.");
	} //close debug
	}while (continueMarker != 'n'); //close while loop
	
	//Display closing messages
	System.out.println("\n\n\nYou have viewed " + counter + " horoscopes.\n\n----------------\n\nGoodbye - please come back again soon.\n\n\n*Program created by Robert Kingston (AKA JawaPro)*");
			    
	} //close MAIN method
} //close program


