import java.io.*;
import java.lang.reflect.*;

// CS100 Fall 2000 Assignment 6.
public class Program6 {

// Display every person in the database.
static void showPeople() {
int n = Person.numberOfPeople();
for (int j=0; j < n; j++){
    Person p = Person.intToPerson(j);
   System.out.println(p);
  }
 }
       
 // Return the person with name s in the database.
 public static Person stringToPerson(String s) {
  int n = Person.numberOfPeople();
  int j=0;

  // loop until the person is found
  while (j < n && !s.equals(Person.intToPerson(j).name()))
   j++;

  // return the person if j is valid
  if (j<n) 
   return Person.intToPerson(j);
  else 
   return null;
 }

 public static void main(String args[]) {
  // initialize Text object in to read from standard input.
  TokenReader in = new TokenReader(System.in);

  // take in the first command
  System.out.print("> "); 
  String s = in.readString();

  // begin the loop that processes each command
  while ( !s.equals("q")){        
                
   /* process command s. */
   if ( s.equals("b"))
    new Person(in.readString(), true);
   else if ( s.equals("g"))
    new Person(in.readString(), false);
   else if ( s.equals("?"))
    System.out.println(stringToPerson(in.readString()));                    
   else if ( s.equals("p"))
    showPeople();                   
   else if ( s.equals("m")){
   	Person p1 = stringToPerson(in.readString());
   	Person p2 = stringToPerson(in.readString());
   	if (p1 == null || p2 == null)
   		System.out.println("no such person");
	else Person.marry(p1, p2);
   }
   else if ( s.equals("s") || s.equals("d") ){
    Person mom;
    Person dad;
    Person p = stringToPerson(in.readString());
    String ch = in.readString();
    if (p==null)
    	System.out.println("no such person");
    else {
   		if ( p.male() ){
     	dad = p;
     	mom = p.other();
    	}
   		else {
     		mom = p;
     		dad = p.other();
    		}
    	Person.child(mom, dad, ch , s.equals("s"));
    	}
   }
   
   // Get next query
   System.out.print("> ");
   System.out.flush();
   s = in.readString();
  }
 }
}

public class CUCSApplication
{
	
	public static void main(String args[])
	{
		Program6.main(new String [0]);
	}

}




