Mr. M's Code

/*
 * Creator: Nighthawk Coding Society
 * Mini Lab Name: Hello Series,featuring Monkey Jumpers
 */

/**
 * Class for Monkeys: a 2D array of Monkeys
 * As well as method to print the Poem
 */
class MonkeyLoop {
    //The area between class definition and the 1st method is where we keep data for object in Java
    String [][] monkeys;    //2D Array: AP CSA Unit 8: 2D array of strings
                            //2D array is like a grid [x][y]
                            // or like a spreadsheet [row][column]

    /**
     * Constructor initializes a 2D array of Monkeys
     */
    public MonkeyLoop() {
        //Storing Data in 2D arrays
        monkeys = new String[][]{   //2D array above is just a name, "new" makes a container ("object")
                //Monkey 0
                {
                        "ʕง ͠° ͟ل͜ ͡°)ʔ ",      //[0][0] eyes
                        "  \\_⏄_/  ",      //[0][1] chin
                        "  --0--   ",       //[0][2] body
                        "  ⎛   ⎞   "        //[0][3] legs
                },
                //Monkey 1
                {
                        " ʕ༼ ◕_◕ ༽ʔ",       //[1][0]
                        "  \\_⎏_/  ",
                        "  ++1++  ",
                        "   ⌋ ⌊   "
                },
                //Monkey 2
                {
                        " ʕ(▀ ⍡ ▀)ʔ",       //[2][0]
                        "  \\_⎐_/ ",
                        "  <-2->  ",
                        "  〈  〉 "
                },
                //Monkey 3
                {
                        "ʕ ͡° ͜ʖ ° ͡ʔ",        //[3][0]
                        "  \\_⍾_/  ",
                        "  ==3==  ",
                        "  _/ \\_  "
                },
                //Monkey 4
                {
                        "  (◕‿◕✿) ",          //[4][0]
                        "  \\_⍾_/ ",          //[4][1]
                        "  ==4==  ",          //[4][2]
                        "  _/ \\_ "           //[4][3]
                },

        };
    }

    /**
     * Loop and print monkeys in array
     * ... repeat until you reach zero  ...
     */
    public void printPoem() {
        //begin the poem
        System.out.println();
        System.out.println("Monkey Jumpers Poem in Java Loopy");

        // monkeys (non-primitive) defined in constructor knows its length
        int monkeyCount = monkeys.length;
        for (int i = monkeyCount; i >= 1; i--)  //loops through 2D array length backwards
        {

            //this print statement shows current count of Monkeys
            //  concatenation (+) of the loop variable and string to form a countdown message
            System.out.println(i + " little monkeys jumping on the bed...");

            //how many separate parts are there in a monkey monkey?
            for (int row = 0; row < monkeyCount; row++) {  //cycles through "cells" of 2d array

                /*cycles through columns to print
                each monkey part by part, will eventually print entire column*/
                for (int col = 0; col < monkeys[row].length; col++) {

                    // prints specific part of the monkey from the column
                    System.out.print(monkeys[row][col] + " ");

                    //this is new line between separate parts
                    System.out.println();
                }

                //this new line gives separation between stanza of poem
                System.out.println();
            }

            //countdown for poem, decrementing monkeyCount variable by 1
            monkeyCount -= 1;
        }

        //out of all the loops, prints finishing messages
        System.out.println("No more monkeys jumping on the bed");
        System.out.println("0000000000000000000000000000000000");
        System.out.println("             THE END              ");
    }

    /**
    * A Java Driver/Test method that is the entry point for execution
    */
    public static void main(String[] args)  {
        new MonkeyLoop().printPoem();   //a new monkey list and output in one step
    }

}
MonkeyLoop.main(null);
Monkey Jumpers Poem in Java Loopy
5 little monkeys jumping on the bed...
ʕง ͠° ͟ل͜ ͡°)ʔ  
  \_⏄_/   
  --0--    
  ⎛   ⎞    

 ʕ༼ ◕_◕ ༽ʔ 
  \_⎏_/   
  ++1++   
   ⌋ ⌊    

 ʕ(▀ ⍡ ▀)ʔ 
  \_⎐_/  
  <-2->   
  〈  〉  

ʕ ͡° ͜ʖ ° ͡ʔ 
  \_⍾_/   
  ==3==   
  _/ \_   

  (◕‿◕✿)  
  \_⍾_/  
  ==4==   
  _/ \_  

4 little monkeys jumping on the bed...
ʕง ͠° ͟ل͜ ͡°)ʔ  
  \_⏄_/   
  --0--    
  ⎛   ⎞    

 ʕ༼ ◕_◕ ༽ʔ 
  \_⎏_/   
  ++1++   
   ⌋ ⌊    

 ʕ(▀ ⍡ ▀)ʔ 
  \_⎐_/  
  <-2->   
  〈  〉  

ʕ ͡° ͜ʖ ° ͡ʔ 
  \_⍾_/   
  ==3==   
  _/ \_   

3 little monkeys jumping on the bed...
ʕง ͠° ͟ل͜ ͡°)ʔ  
  \_⏄_/   
  --0--    
  ⎛   ⎞    

 ʕ༼ ◕_◕ ༽ʔ 
  \_⎏_/   
  ++1++   
   ⌋ ⌊    

 ʕ(▀ ⍡ ▀)ʔ 
  \_⎐_/  
  <-2->   
  〈  〉  

2 little monkeys jumping on the bed...
ʕง ͠° ͟ل͜ ͡°)ʔ  
  \_⏄_/   
  --0--    
  ⎛   ⎞    

 ʕ༼ ◕_◕ ༽ʔ 
  \_⎏_/   
  ++1++   
   ⌋ ⌊    

1 little monkeys jumping on the bed...
ʕง ͠° ͟ل͜ ͡°)ʔ  
  \_⏄_/   
  --0--    
  ⎛   ⎞    

No more monkeys jumping on the bed
0000000000000000000000000000000000
             THE END              

The Three Wise Monkeys and That One Other Monkey

class MonkeyLoop {
    //The area between class definition and the 1st method is where we keep data for object in Java
    String [][] monkeys;    //2D Array: AP CSA Unit 8: 2D array of strings
                            //2D array is like a grid [x][y]
                            // or like a spreadsheet [row][column]

    /**
     * Constructor initializes a 2D array of Monkeys
     */
    public MonkeyLoop() {
        //Storing Data in 2D arrays
        monkeys = new String[][]{   //2D array above is just a name, "new" makes a container ("object")
                //Monkey 0
                {
                        "       .-''-.      ",      //[0][0]
                        "     _/_- .-_\\_    ",      //[0][1]
                        "    / __}  {__ \\   ",      //[0][2]
                        "   / //  ''  \\\\ \\  ",      //[0][3]
                        "  / / \\'----'/ \\ \\ ",      //[0][4]
                        "  \\ \\_/`''''`\\_/ / ",      //[0][5]
                        "   \\            /  ",      //[0][6]
                        "-={ see no evil }=-",      //[0][7]
                },
                //Monkey 1
                {
                        "       .-''-.       ",       //[1][0]
                        "     _/.-..-.\\_     ",       //[1][1]
                        "    /|( o  o )|\\    ",       //[1][2]
                        "   | //  ''  \\\\ |   ",       //[1][3]
                        "  / / \\'----'/ \\ \\  ",       //[1][4]
                        "  \\ \\_/`''''`\\_/ /  ",       //[1][5]
                        "   \\            /   ",       //[1][6]
                        "-={ hear no evil }=-",       //[1][7]
                },
                //Monkey 2
                {
                        "        .-''-.       ",       //[2][0]
                        "      _/.-..-.\\_     ",       //[2][1]
                        "     ( ( o  o ) )    ",       //[2][2]
                        "      |/  ''  \\|     ",       //[2][3]
                        "       \\'/^^\\'/      ",       //[2][4]
                        "       /`\\  /`\\      ",       //[2][5]
                        "      /  /||\\  \\     ",       //[2][6]
                        "-={ speak no evil }=-",       //[2][7]
                },
                //Monkey 3
                {
                        "      .-''-.      ",        //[3][0]
                        "    _/.-..-.\\_    ",        //[3][1]
                        "   ( ( o  o ) )   ",        //[3][2]
                        "    |/  ''  \\|    ",        //[3][3]
                        "     \\ .--. /     ",        //[3][4]
                        "     /`''''`\\     ",        //[3][5]
                        "    /        \\    ",        //[3][6]
                        "-={ have no fun }=-",       //[3][7]
                },
        };
    }

    /**
     * Loop and print monkeys in array
     * ... repeat until you reach zero  ...
     */
    public void printWiseMonkeys() {
        //begin the poem
        System.out.println();
        System.out.println("Three Wise Monkeys and that other monkey");

        // monkeys (non-primitive) defined in constructor knows its length
        int monkeyCount = monkeys.length;

        //how many separate parts are there in a monkey monkey?
        for (int row = 0; row < monkeyCount; row++) {  //cycles through "cells" of 2d array

            /*cycles through columns to print
            each monkey part by part, will eventually print entire column*/
            for (int col = 0; col < monkeys[row].length; col++) {

                // prints specific part of the monkey from the column
                System.out.print(monkeys[row][col] + " ");

                //this is new line between separate parts
                System.out.println();
            }

            //this new line gives separation between stanza of poem
            System.out.println();
        }
        for (int col = 0; col < monkeys[0].length; col++) {
            for (int row = 0; row < monkeyCount; row++) {  

                // prints specific part of the monkey from the column
                System.out.print(monkeys[row][col] + " ");

            }
            System.out.println(); //this is new line between separate parts
        }
    }

    /**
    * A Java Driver/Test method that is the entry point for execution
    */
    public static void main(String[] args)  {
        new MonkeyLoop().printWiseMonkeys();   //a new monkey list and output in one step
    }

}
MonkeyLoop.main(null);
Three Wise Monkeys and that other monkey
       .-''-.       
     _/_- .-_\_     
    / __}  {__ \    
   / //  ''  \\ \   
  / / \'----'/ \ \  
  \ \_/`''''`\_/ /  
   \            /   
-={ see no evil }=- 

       .-''-.        
     _/.-..-.\_      
    /|( o  o )|\     
   | //  ''  \\ |    
  / / \'----'/ \ \   
  \ \_/`''''`\_/ /   
   \            /    
-={ hear no evil }=- 

        .-''-.        
      _/.-..-.\_      
     ( ( o  o ) )     
      |/  ''  \|      
       \'/^^\'/       
       /`\  /`\       
      /  /||\  \      
-={ speak no evil }=- 

      .-''-.       
    _/.-..-.\_     
   ( ( o  o ) )    
    |/  ''  \|     
     \ .--. /      
     /`''''`\      
    /        \     
-={ have no fun }=- 

       .-''-.              .-''-.                .-''-.              .-''-.       
     _/_- .-_\_          _/.-..-.\_            _/.-..-.\_          _/.-..-.\_     
    / __}  {__ \        /|( o  o )|\          ( ( o  o ) )        ( ( o  o ) )    
   / //  ''  \\ \      | //  ''  \\ |          |/  ''  \|          |/  ''  \|     
  / / \'----'/ \ \    / / \'----'/ \ \          \'/^^\'/            \ .--. /      
  \ \_/`''''`\_/ /    \ \_/`''''`\_/ /          /`\  /`\            /`''''`\      
   \            /      \            /          /  /||\  \          /        \     
-={ see no evil }=- -={ hear no evil }=- -={ speak no evil }=- -={ have no fun }=- 

Hack Questions

Is this program in more of an Imperative Programming Style or OOP Style? Explain.

This program is more of an Imperative Programming Style since we didn't use objects, which would be found in Object Oriented Programming. Each individual monkey is not an object, but rather is an image that is made up of an individual string on each line. The purpose of object oriented programming is more for working with data sets and manipulating them whereas imperative programming where every step has every step coded in, just like we have here.

Are the monkeys objects?

No, the monkeys are not objects.

How to access 2-D arrays?

You can access the 2-D array by using the row index value and column index value: Name_of_the arrays[row_index][column_index];