// *************************************************************
// Name:         Mohamed Aboutabl
// Date:         10/05/2004
// Assignment:   Lab 13: TestNames.java
//
// *************************************************************
// References & Acknowledgements: I received no outside help
//
// *************************************************************
// Name of the class:	TestNames
// Purpose of the class: Test the Name class
// *************************************************************

import cs1.Keyboard ;

public class TestNames
{
	/**----------------------------------------------------------
	// Test drive the Name class and its member methods
	// --------------------------------------------------------*/
	public static void main( String[] args)
	{
		// Variables Declarations

		Name name1 , name2 ;	// Objects for the two names
		String	first1, middle1, last1 ,	// Parts of Name #1
					first2, middle2, last2 ;	// Parts of Name #2
		String n1 , n2;
		boolean sameName ;
					
		// Get the first person's name from the user
		System.out.println("Enter the following for the first person:");
		System.out.print("\tFirst name: ");
		first1 = Keyboard.readString() ;
		System.out.print("\tMiddle name: ");
		middle1 = Keyboard.readString() ;
		System.out.print("\tLast name: ");
		last1 = Keyboard.readString() ;
		
		name1 = new Name(first1, middle1, last1);

		// Get the second person's name from the user
		System.out.println("\nNow, enter the following for the second person:");
		
		/*
		System.out.print("\tFirst name: ");
		first2 = Keyboard.readString() ;
		System.out.print("\tMiddle name: ");
		middle2 = Keyboard.readString() ;
		System.out.print("\tLast name: ");
		ast2 = Keyboard.readString() ;
		name2 = new Name(first2, middle2, last2);
		*/
		
		// name2 = inputName();
		name2 = Name.inputName() ;
		
		// Print the two Name objects via the toString method
		System.out.print("You entered:\n\t");
		System.out.println( name1 ) ;
		System.out.print("and:\n\t");
		System.out.println( name2 ) ;	
		System.out.println();
		
		// Now display the two names in the required format
		System.out.println("\nThe First person's data is:");
		displayName( name1 ) ;
		
		
		System.out.println("\nThe Second person's data is:");
		// displayName( name2 ) ;	
		name2.displayName() ;
		
		// Check if the two names are identical
		n1 = name1.firstMiddleLast() ;
		n2 = name2.firstMiddleLast() ;
		sameName = n1.equalsIgnoreCase(n2) ;
		
		System.out.println("\nAre the names '" + n1 + "' and '" + n2 
			+ "' the same? " + sameName) ;
			
		// Change the first person's last name
		System.out.print("\nEnter the first person's NEW last name: ");
		last1 = Keyboard.readString() ;
		System.out.println( "Before change " + name1 ) ;
		name1.changeLast( last1 ) ;
		System.out.println( "After  change " + name1 ) ;		
						
	}
	
	// ---------------------------------------------------
	// Input the parts of a Name object from the keyboard
	// ---------------------------------------------------
	static Name inputName ()
	{
		String first, middle, last ;
		Name result ;
		
		System.out.print("\tFirst name: ");
		first = Keyboard.readString() ;
		System.out.print("\tMiddle name: ");
		middle = Keyboard.readString() ;
		System.out.print("\tLast name: ");
		last = Keyboard.readString() ;
		
		result = new Name( first, middle , last );
		return result;
	}
	
	// ---------------------------------------------------
	// Display the Name object and its attributes
	// ---------------------------------------------------
	static void displayName( Name n )
	{
		System.out.println("First-Middle-Last version: " + n.firstMiddleLast() );
		System.out.println("Last-First-Middle version: " + n.lastFirstMiddle() );
		System.out.println("Initials: " + n.initials() );
		System.out.println("Length: " + n.length());
		System.out.println("e-mail: " + n.email(6) );	
	}
}