import java.util.Scanner;

/**
 * Holds a person's fullname, and allows access to such information
 * as their first name and last name.
 *
 * @author Zach Tomaszewski
 * @version 21 Sept 2007
 */
public class Fullname {

  private String fullname;
  
  
  /**
   * Constructs a new Fullname object containing the given name.
   */
  public Fullname(String name){
    this.fullname = name;
  }

  
  /**
   * Returns the fullname.
   */
  public String toString() {
    return this.fullname;
  }
  
  
  /**
   * Returns the first name.
   */
  public String getFirstName() {
    int endOfFirstName = this.fullname.indexOf(' ');
    String firstName = this.fullname.substring(0, endOfFirstName);
    return firstName;
  }
  
  /**
   * Returns the last name.
   */
  public String getLastName() {
    int startOfLastName = this.fullname.lastIndexOf(" ") + 1;
    String lastName = this.fullname.substring(startOfLastName);
    return lastName;
  }
  
  /**
   * Returns length of last name.
   */
  public int getLengthOfLastName() {
    String lastname = this.getLastName();
    return lastname.length();
  }
  
  /**
   * Returns the initials, which is the first letter of the first name
   * and the first letter of the last name, capitalized.
   */
  public String getInitials() {
    String initials;
    initials = this.fullname.substring(0, 1);
    initials = initials + ".";
    initials = initials + this.getLastName().substring(0,1);
    initials += ".";  //example of a shortcut assignment operator
    return initials.toUpperCase();
  }
  
  /**
   * Asks the user for their fullname, and then provides
   * some information about their name.
   */
  public static void main(String[] args) {

    Scanner keybd = new Scanner(System.in);
    System.out.print("Enter your full name: ");
    String input = keybd.nextLine();
    Fullname yourName = new Fullname(input);
    
    System.out.println("Your name is: " + yourName.toString());
    System.out.println("Your first name is: " + yourName.getFirstName());
    System.out.println("Your last name is: " + yourName.getLastName());
    System.out.println("The length of your last name is: " + 
        yourName.getLengthOfLastName());
    System.out.println("Your initials are: " + yourName.getInitials());
    
  }

}
