// Menu.java  Li Jin and P. Conrad, for CISC370, 06/14/2007

import java.util.*;
import java.io.*;

/**
 * Class Menu
 * A user can choose to find a person's birthdate in a file, or comapare two people's age.
 * More function can be added to menu.
 * @author Li Jin
 * @version 1.0
 * This is a sample for CISC370. Any suggestions are welcome!
 */

public class Menu {

    public static void main (String[] args) {
	Person person1=new Person();
	Person person2=new Person();
	String line;
	String[] name;
	InputStreamReader reader;
	BufferedReader br;
	try{
	    reader = new InputStreamReader(System.in);
	    br = new BufferedReader(reader);
	    while(true) {

		printMenu();
		line=br.readLine().trim();
		
		if(line.equals("f")) {
		    findPerson(br);
		}
		else if(line.equals("c")) {
		    compareBirthdays(br);
		}
		else if(line.equals("w")) {
		    whosBirthdayIsOnThisDate(br);
		}
		else if(line.equals("q")) {
		    break;
		}
		else {
		    System.out.println("You entered: " + line);
		    System.out.println(" I don't understand that option.");
		}	
		
	    }
	    br.close();
	}
	catch (Exception e){
            e.printStackTrace();
        }
    }

    /**
     *  printMenu prints a menu of options
     */

    public static void printMenu()
    {

	System.out.println(" Menu of options ");
	System.out.println(" =============== ");
	System.out.println(" f  find a person's birthday");
	System.out.println(" w  who has a birthday on a certain date");
	System.out.println(" c  compare two people's ages");
	System.out.println(" q  quit   ");
	System.out.println("");	

	
    }

    /**
     *   find a person
     *   @param br the BufferedReader we are reading the person from (stdin)
     */

    public static void findPerson(BufferedReader br){

	Person person1=new Person();

	person1.setNameFromScreen(br);
	if(person1.existInFile("person.txt")==true)
	    System.out.println(person1.toString());
	else 
	    System.out.println("can not find "+person1.getName());
    }


    /**
     * compare two people's birthdates
     * @param br the BufferedReader we are reading the person from (stdin)
     */

    public static void compareBirthdays(BufferedReader br){

	Person person1=new Person();
	Person person2=new Person();

	person1.setNameFromScreen(br);
	if(person1.existInFile("person.txt")==false){
	    System.out.println("can not find "+person1.getName());
	    return;
	}
	person2.setNameFromScreen(br);
	if(person2.existInFile("person.txt")==false){
	    System.out.println("can not find "+person2.getName());
	    return;
	}
	if(person1.equalBirthDate(person2)==true)
	    System.out.println(person1.getName() 
			       + " and " + person2.getName()
			       + " have same birthdate " 
			       + person1.getBirthDate().toString());
	else
	    System.out.println(person1.getName()
			       + " " + person1.getBirthDate().toString()
			       + " and " + person2.getName()
			       + " " + person2.getBirthDate().toString()
			       + " have diffirent birthdates.");
    }
    
    
    void whosBirthdayIsOnThisDate(BufferedReader br)
    {
	System.out.println("Who's birthday is on this date... (stub... not implemented yet)");
    }


}



