package variables;

public class Variables {
    public static void main(String[] args) {

        /*
         * Variable Declaration in Java:
         * type varName;
         * type = the data type or class/reference type
         * varName = the variable identifier
         * Syntax for variable identifiers (same as Classes)
         * - can't start with a digit
         * - can't contain symbols (including spaces) except _ and $
         * - can't be a Java reserved word,
         * nor can it be "true", "false", or "null"
         * Industry Standards for variable identifiers:
         * - starts with a lower-case letter
         * - self-documenting
         * - camel case
         */

        // one of each type we use most often, initialized with null values
        String string = "";
        int number = 0;
        double value = 0.0;
        boolean foo = false; // the boolean version of null is false
        char key = '\0'; // NOT '' -- \0 is a char version of null

        // notice how the null values for string and char appear
        System.out.println(string + ", " + number + ", " + value + ", "
                + foo + ", " + key);

        // an easier and more efficient way to print when you have
        // a lot of concatenation (same as System.out.format()):
        System.out.printf("%s, %d, %f, %b, %c \n", string, number, value,
                foo, key);
        /*
         * NOTES:
         * %s is the format specifier for all strings
         * %d is the format specifier for all integers
         * %f is the format specifier for all floating points
         * %.nf replace "n" with the # of decimal places
         * e.g. %.2f formats with 2 decimal places
         * %b is the format specifier for booleans
         * %B prints it in upper-case instead of lower-case
         * %c is the format specifier for characters
         * 
         * We add \n (or you can use %n) to add a newline to the end
         * because printf() is like print() - it doesn't add a newline
         * to the end of the output.
         * 
         * More information in the Session 1.2 materials
         */

        // Recall this:
        int x = 2;
        int y = 5;
        System.out.println(y / x);
        // integer division!

        /*
         * Recall that:
         * When one or both operands is a floating point, you get a floating
         * point result.
         * e.g. 5 / 2.0 = 2.5, 5.0 / 2 = 2.5, 5.0 / 2.0 = 2.5
         * When both operands are integers, you get an integer result;
         * any decimal or fractional portion is removed (NOT rouned)
         * e.g. 5 / 2 = 2
         *
         * When using literals, you can just add .0 to an integer to make it
         * a floating point number.
         * For variables, you will have to CAST:
         * Casting operator: (type)
         * e.g. (double)x and/or (double)y
         * - the "type" in the parentheses is the type you want to
         * convert into
         */
        // try it
        // System.out.println((double)y / x);

        /*
         * Implicit vs Explicit Casting
         * Sometimes values will cast automatically (implicitly)
         * - placing an int into a double
         * - placing a char into an int or a long
         * There are a couple of others, and some things to make note of,
         * and you can read more about that in the Session 1.2 materials.
         */

        // double dx = x;  // recall x is an int
        // System.out.printf("integer x: %d\ndouble x: %f\n", x, dx);
        // feel free to add decimal places to the %f!

    }
}
