package staticmethods;

public class Methods1 {
    public static void main(String[] args) {
        /*
         * In Java, functions are called "methods".
         * e.g. println(), print(), printf() are all methods.
         * In Java, all methods belong to some kind of class
         * or object. For example, println(), print(), and 
         * printf() all belong to the PrintStream class (System.out 
         * is an instance of PrintStream)
         * 
         * It's almost always necessary to write your own methods.
         * Why?
         * - modularity: creating methods allows you to break up complex 
         * logic into smaller tasks that are easier to debug/maintain
         * - reusability: you can re-use methods in many different 
         * programs instead of coding the same set of statements 
         * many times
         * - abstraction: you can hide complex logic and calculations
         * so that other programmers only need to worry about "what 
         * goes in and what comes out" - also called the "black box"
         * (you don't need to see what's going on inside the box, 
         * you can use the box without knowing what's inside it)
         * 
         * Important: Don't create a method just for the sake of 
         * creating a method! There needs to be a "value added".
         * In otherwords, to break up a complex program into tasks 
         * (modularity), to re-use code in other programs, or to 
         * hide complex and unnecessary details (abstraction).
         */

         // calling a method defined in the same class:  qualifier not needed
         displayGreeting();

         /*
          * "Qualifier" is the thing in front of the method e.g.
          * Math.pow(5, 2) - pow() is qualified by Math
          * input.nextInt() - nextInt() is qualified by input
          * The qualifier tells the compiler who the method belongs to, 
          * where the method's code is (i.e. "in the Math class" or 
          * "in the 'input' object's class")
          * When you have no qualifier, the compiler looks inside the 
          * current class for that method.
          * So when the method you are calling is in the same class, no 
          * qualifier is needed.
          *
          * NOTE for OOP Programmers: if you are familiar with the "this" 
          * keyword, that will NOT work on static methods because there is 
          * no "this", there is no object.
          */

    }

    public static void displayGreeting() {
        String[] greetings = {"Hello", "Aloha", 
        "Namaste", "Hola", "Guten Tag", "Salve", "Bonjour",
        "Konnichiwa", "Asalaam Alaikum", "Annyeonghaseyo", 
        "Merhaba", "Dzien Dobry"};

        System.out.println(greetings[(int)(Math.random() * greetings.length)]);
    }
    
}
