// *************************************************************
// Name:         Mohamed Aboutabl
// Date:         10/07/2004
// Assignment:   Lab 14: Name.java
//
// *************************************************************
// References & Acknowledgements: I received no outside help
//
// *************************************************************

import cs1.Keyboard ;

public class Name
{
	/**----------------------------------------------------------
	//
	// Name of the class:		Name
	// Purpose of the class: 	Manipulation of peoples' Names
	//
	// --------------------------------------------------------*/

	private String fName , mName, lName ; // Name parts
	
	// ---------------------------------------------------
	// The constructor method
	// ---------------------------------------------------
	public Name( String first, String middle, String last)
	{
		// Initialize the data member of the Name class
		fName = first ;
		mName = middle ;
		lName = last ;
	}
	
	// ---------------------------------------------------
	// return the String version of a Name object
	// ---------------------------------------------------
	public String toString()
	{
		String result;
		
		result = "Name: " + fName + "," + mName + "," + lName ;
		return result ;
	}

	// ---------------------------------------------------
	// Get the first name to the caller
	// ---------------------------------------------------
	public String getFirst()
	{
		return fName ;
	}
	
	// ---------------------------------------------------
	// Get the middle name to the caller
	// ---------------------------------------------------
	public String getMiddle()
	{
		return mName ;
	}
	
	// ---------------------------------------------------
	// Get the last name to the caller
	// ---------------------------------------------------
	public String getLast()
	{
		return lName ;
	}
	
	// ---------------------------------------------------
	// Get the first-middle-last name to the caller
	// ---------------------------------------------------
	public String firstMiddleLast()
	{
		return fName + " " + mName + " " + lName ;
	}

	// ---------------------------------------------------
	// Get the last-first-middle name to the caller
	// ---------------------------------------------------
	public String lastFirstMiddle()
	{
		return lName + ", " + fName + " " + mName ;
	}
	
	// ---------------------------------------------------
	// Get the initials in uppercase
	// ---------------------------------------------------
	public String initials()
	{
		String result;

		// get the first character of each name part
		result = fName.substring(0,1) + mName.substring(0,1) + lName.substring(0,1);
		
		// now make sure it's all in upper case
		result = result.toUpperCase() ;
		
		return result;
	}
	
	// ---------------------------------------------------
	// Get the JMU e-mail ID
	// ---------------------------------------------------
	public String email(int length)
	{
		String result;
		
		// Get the leftmost 'length' characters of the last name
		result = lName.substring(  0 , length ) ;
		
		// Now, concatenate that to the first and middle initials
		result = result + fName.substring(0,1) + mName.substring(0,1) ;
		
		return result;
	}
	
	// ---------------------------------------------------
	// Change the last name
	// ---------------------------------------------------
	public void changeLast( String newLast )
	{
		lName = newLast ;
	}

	// ---------------------------------------------------
	// Compute the total length of the name
	// ---------------------------------------------------
	public int length()
	{
		int result ;
		
		result = fName.length() + mName.length() + lName.length() ;
		
		return result;
	}	

	// ---------------------------------------------------
	// Input the parts of a Name object from the keyboard
	// ---------------------------------------------------
	public 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
	// ---------------------------------------------------
	public void displayName()
	{
		System.out.println("First-Middle-Last version: " + firstMiddleLast() );
		System.out.println("Last-First-Middle version: " + lastFirstMiddle() );
		System.out.println("Initials: " + initials() );
		System.out.println("Length: " + length());
		System.out.println("e-mail: " + email(6) );	
	}

}  // of class Name