/*
 * NameAnalyzerExtendedWithMethods.java
 * Computer Science S-111
 *
 * This version of our extended name analyzer uses two separate methods
 * to extract and return the first and last names.
 * 
 * Note that the firstName and lastName methods do *not* do any printing.
 * Rather, they return the name being requested, and then the main
 * method prints the return value.
 */

import java.util.*;

public class NameAnalyzerExtendedWithMethods {
    /*
     * firstName - takes a String of the form "firstname lastname" 
     * and extracts and returns the firstname component of the name.
     */
    public static String firstName(String name) {
        int spaceIndex = name.indexOf(' ');
        String first = name.substring(0, spaceIndex);
        return first;
    }
    
    /*
     * lastName - takes a String of the form "firstname lastname" 
     * and extracts and returns the lastname component of the name.
     */
    public static String lastName(String name) {
        int spaceIndex = name.indexOf(' ');        
        return name.substring(spaceIndex + 1);
    }

    /*
     * printVertical - takes a String and prints it "vertically",
     * with each character on its own line.
     */
    public static void printVertical(String str) {
        for (int i = 0; i < str.length(); i++) {
            System.out.println(str.charAt(i));
        }
    }
        
    public static void main(String[] args) {
        Scanner console = new Scanner(System.in);
        String name = console.nextLine();
        System.out.println("full name = " + name);

        // Get and print the length.
        int length = name.length();
        System.out.println("length = " + length);

        // Extract and print the first name.
        // We put the method call inside the println statement.
        // The return value will replace the method call and be printed!
        String first = firstName(name);
        System.out.println("first name = " + first);
        
        // Extract and print the last name.
        System.out.println("last name = " + lastName(name));
        
        printVertical(name);
    }
}
