/**
 * A small program to demonstrate how to read values typed by the user.
 * Excessively commented to explain what is going on.
 */

// static final variables are called constants and don't change value
// We use constants to give names to "magic numbers", messages, etc.

/** The current legal drinking age */
public static final int DRINKING_AGE = 21;

/**
 * Program prompts the user for name and age and uses the values.
 */
void main() {

    // Prompt the user for a name
    IO.println("What is your name?");

    // Read a line of user input and store it in a variable.
    String name = IO.readln();

    // This time, prompt and read the string in one step
    String ageStr = IO.readln("What is your age? ");

    // Convert the string to an integer
    // If user doesn't type an int, there will be an error here.
    int age = Integer.parseInt(ageStr);

    // Let's greet the user by name.
    // We can use the + operator to concatenate Strings
    IO.println("Hello, " + name + ".");

    // if/else lets us choose branches
    if(age < DRINKING_AGE) {
        IO.println("You are too young to go drinking.");
    } else {
        IO.println("You are allowed to buy alcohol.");
    }

    // Using a String method to get length of name
    IO.println("Your name has " + name.length() + " characters.");

    // Using a Math method to compute square root
    IO.println("The square root of your age is " + Math.sqrt(age));

    // Selecting a random number.
    // The Math.random method gives a double in the range [0.0, 1.0)
    IO.println("A random number is: " + Math.random());

    // Pretend we are rolling a 6 sided die.
    int dieRoll = (int)(Math.random()*6) + 1;
    IO.println("A random die roll = " + dieRoll);
}
