// Arup Guha
// 3/22/2026
// Example illustrating ArrayList and StringTokenizer
// Sorting People by Age - People class

import java.util.*;

public class Person implements Comparable<Person> {

	private String name;
	private String firstName;
	private String[] middleNames;
	private String lastName;
	private Date dateOfBirth;
	private Time timeOfBirth;
	
	public Person(String fullname, String dob, String tob) {
		
		// Just for printing!
		name = fullname;
		
		// Create a default String Tokenizer with the whole name.
		StringTokenizer tok = new StringTokenizer(fullname);
		
		// Grab this.
		firstName = tok.nextToken();
		
		// Make this the right size and copy these in.
		middleNames = new String[tok.countTokens()-1];
		for (int i=0; i<middleNames.length; i++)
			middleNames[i] = tok.nextToken();
	
		// This is the last name,
		lastName = tok.nextToken();
		
		// The delimiter for the date is the forward slash.
		tok = new StringTokenizer(dob, "/");
		int yr = Integer.parseInt(tok.nextToken());
		int mon = Integer.parseInt(tok.nextToken());
		int day = Integer.parseInt(tok.nextToken());
		dateOfBirth = new Date(yr, mon, day);
		
		// The delimiter for the time is the colon.
		tok = new StringTokenizer(tob, ":");
		int hr = Integer.parseInt(tok.nextToken());
		int min = Integer.parseInt(tok.nextToken());
		timeOfBirth = new Time(hr, min);
	}
	
	// How the problem wanted us to print.
	public String toString() {
		return name;
	}
	
	public int compareTo(Person other) {
	
		// First tie breaker.
		int tmp = this.dateOfBirth.compareTo(other.dateOfBirth);
		if (tmp != 0) return tmp;
		
		// Now time.
		tmp = this.timeOfBirth.compareTo(other.timeOfBirth);
		if (tmp != 0) return tmp;
		
		// Last name.
		tmp = this.lastName.compareTo(other.lastName);
		if (tmp != 0) return tmp;
		
		// First name.
		tmp = this.firstName.compareTo(other.firstName);
		if (tmp != 0) return tmp;
		
		// Now go through the middle names.
		for (int i=0; i<this.middleNames.length && i<other.middleNames.length; i++) {
			tmp = this.middleNames[i].compareTo(other.middleNames[i]);
			if (tmp != 0) return tmp;
		}
		
		// Last and final tie-breaker!
		return this.middleNames.length - other.middleNames.length;
	}
	
	
}