/**
 * ImprovedEchoBot - EchoBot with a sendMessage method
 * This example adds a method that manages the entire message flow.
 *
 * Part III of the book "Introduction to Programming in Java"
 */

public class ImprovedEchoBot {
    private static final String BOT_TEMPLATE = "BOT: %s";
    private static final String USER_TEMPLATE = "USER: %s";

    /**
     * Method that responds to a user message.
     * @param message The user's message
     * @return The bot's response
     */
    public static String respond(String message) {
        return "I can hear you! You said: " + message;
    }

    /**
     * Method that sends a message to the bot and displays the dialogue.
     * @param message The user's message
     */
    public static void sendMessage(String message) {
        // Displays the user's message
        System.out.println(String.format(USER_TEMPLATE, message));

        // Gets the bot's response
        String response = respond(message);

        // Displays the bot's response
        System.out.println(String.format(BOT_TEMPLATE, response));
    }

    public static void main(String[] args) {
        sendMessage("Hello!");
        sendMessage("How are you?");
    }
}
