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 CSIC370. 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){
		System.out.println("========Menu=======\n"+
				   "*Find person: Press 1\n"+
				   "*Compare two people's age: Press 2\n"+
				   "*Exit: Press 0\n");	    

		line=br.readLine();
		if(line.trim().equals("1")) {//find a person
		    person1.setNameFromScreen(br);
		    if(person1.existInFile("person.txt")==true)
			System.out.println(person1.toString());
		    else 
			System.out.println("can not find "+person1.getName());
		}
		else if(line.trim().equals("2")) {//compare two people's birthdates
		    person1.setNameFromScreen(br);
		    if(person1.existInFile("person.txt")==false){
			System.out.println("can not find "+person1.getName());
			continue;
		    }
		    person2.setNameFromScreen(br);
		    if(person2.existInFile("person.txt")==false){
                        System.out.println("can not find "+person2.getName());
                        continue;
                    }
		    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.");
		}
		else if(line.trim().equals("0")) break;
		
	    }
	    br.close();
	}
	catch (Exception e){
            e.printStackTrace();
        }
    }
}


