package scannerinput;

import java.util.Scanner;

public class InputStrings {
    public static void main(String[] args) {

        /*
         * There are two ways to get Strings using a Scanner.
         * 
         * next() will only read up to the first whitespace entered at the
         * keyboard.
         * Whitespace = space, tab, enter key (newline)
         * Note that if the user types in more stuff after a whitespace
         * key, that stuff is sitting in the input buffer, waiting to
         * be read!
         * Use this method only when you are only concerned with the first
         * word of the input.
         * 
         * nextLine() will read in everything up to the newline (enter key)
         * character and return it. Use this method when you want to get
         * multiple words, or any input that might have spaces (assuming
         * you want to capture those spaces).
         */

        Scanner in = new Scanner(System.in);

        System.out.print("Enter some words: ");

        /*
         * next() reads characters from the input buffer, but only 
         * up to the first whitespace character (space, tab, newline)
         */
        String input = in.next();
        System.out.println(input);
        // is there anything left in there?
        System.out.println("*" + in.nextLine() + "*");

        // get all the words that are input:
        System.out.print("Enter more words: ");

        /*
         * nextLine() reads all the characters from the input buffer,
         * and stops when it sees a newline character.
         */
        String words = in.nextLine();
        System.out.println("You typed this:\n" + words);

        // EXTRA: how do you get a single char (character)?
        System.out.print("Are you tired? (Y/N)");

        /*
         * in.next() grabs a word, regardless of how many characters the 
         * user typed
         * charAt(0) grabs the first character of the word that was returned 
         * by in.next() - the 0 is the index of the first character
         */
        char answer = in.next().charAt(0);

        /*
         * Character is a class containing static methods you can use to 
         * do some kinds of character operations. toUpperCase() converts 
         * the char to an upper-case character (if it's not a letter, nothing 
         * happens). We add this because we don't know what case the user 
         * will use for their answer: y or Y?
         * Using toUpperCase() is much easier than typing:
         * if (answer == 'y' || answer == 'Y') { ... }
         * 
         * Also, you could have just used:
         * char answer = in.next().toUpperCase().charAt(0);
         * (get the first word, convert it to all upper-case, then grab 
         *  the first character)
         */
        if (Character.toUpperCase(answer) == 'Y') {
            System.out.println("zzzzzzzzzzz....");
        } else {
            System.out.println("woot!");
        }
        in.close();
    }
}
