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              

Bats and More Lines of the Song

class BatLoop {

    String [][] bats;    


    public BatLoop() {

        bats = new String[][]{  // added bats instead of monkeys!
                //Bat 0
                {
                " /\\      hetvi       /\\  ",
                "/ \\'._   (\\_/)   _.'/ \\ ",
                "|.''._'--(o.o)--'_.''.| ",
                " \\_ / `;=/   \\=;` \\ _/  ",
                "   `\\__| \\___/ |__/`    ",
                "        \\(_|_)/         ",
                },
                //Bat 1
                {
                " /\\      brian       /\\  ",
                "/ \\'._   (\\_/)   _.'/ \\ ",
                "|.''._'--(o.o)--'_.''.| ",
                " \\_ / `;=/   \\=;` \\ _/  ",
                "   `\\__| \\___/ |__/`    ",
                "        \\(_|_)/         ",  
                },
                //Bat 2
                {
                " /\\      ellen       /\\  ",
                "/ \\'._   (\\_/)   _.'/ \\ ",
                "|.''._'--(o.o)--'_.''.| ",
                " \\_ / `;=/   \\=;` \\ _/  ",
                "   `\\__| \\___/ |__/`    ",
                "        \\(_|_)/         ",
                },
                //Bat 3
                {
                " /\\      jazair      /\\  ",
                "/ \\'._   (\\_/)   _.'/ \\ ",
                "|.''._'--(o.o)--'_.''.| ",
                " \\_ / `;=/   \\=;` \\ _/  ",
                "   `\\__| \\___/ |__/`    ",
                "        \\(_|_)/         ",
                },
                //Bat 4
                {
                " /\\      Mr. M       /\\  ",
                "/ \\'._   (\\_/)   _.'/ \\ ",
                "|.''._'--(o.o)--'_.''.| ",
                " \\_ / `;=/   \\=;` \\ _/  ",
                "   `\\__| \\___/ |__/`    ",
                "        \\(_|_)/         ",
                },

        };
    }


    public void printPoem() {

        System.out.println();
        System.out.println("Bat Jumpers Poem in Java Loopy");

        int batCount = bats.length;
        for (int i = batCount; i >= 1; i--) 
        {

            for (int row = 0; row < batCount; row++) {

                for (int col = 0; col < bats[row].length; col++) {

                    System.out.print(bats[row][col] + " ");

                    System.out.println();
                }

                System.out.println();
            }
// Added the rest of the poem under the bat print
            if (i > 1){
                System.out.println(i + " little bats jumping on the bed...");
            }
            else{
                System.out.println(i + " little bats jumping on the bed...");
            }
            
            System.out.println("One fell down and bumped his head!");
            System.out.println("Mama called the doctor and the doctor said:");
            if (i == 1){   
                System.out.println("Put those bats right to bed!");
            }
            else{
                System.out.println("No more bats jumping on the bed!");
            }
            System.out.println();

            batCount -= 1;
        }

        System.out.println("All the bats are off the bed!");
        System.out.println("Bye Bye Bats");
    }

    public static void main(String[] args)  {
        new BatLoop().printPoem();   
    }

}
BatLoop.main(null);
Bat Jumpers Poem in Java Loopy
 /\      hetvi       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      brian       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      ellen       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      jazair      /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      Mr. M       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

5 little bats jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more bats jumping on the bed!

 /\      hetvi       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      brian       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      ellen       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      jazair      /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

4 little bats jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more bats jumping on the bed!

 /\      hetvi       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      brian       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      ellen       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

3 little bats jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more bats jumping on the bed!

 /\      hetvi       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

 /\      brian       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

2 little bats jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more bats jumping on the bed!

 /\      hetvi       /\   
/ \'._   (\_/)   _.'/ \  
|.''._'--(o.o)--'_.''.|  
 \_ / `;=/   \=;` \ _/   
   `\__| \___/ |__/`     
        \(_|_)/          

1 little bats jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
Put those bats right to bed!

All the bats are off the bed!
Bye Bye Bats
class MonkeyLoop {

    String [][] monkeys;    


    public MonkeyLoop() {

        monkeys = new String[][]{  
                //Monkey 0
                {
                        "ʕง ͠° ͟ل͜ ͡°)ʔ ",      //[0][0] eyes
                        "  \\_⏄_/   ",      //[0][1] chin
                        "---hetvi--  ",       //[0][2] body
                        "   ⎛   ⎞    "        //[0][3] legs
                },
                //Monkey 1
                {
                        " ʕ༼ ◕_◕ ༽ʔ  ",       //[1][0]
                        "  \\_⎏_/    ",
                        " +++brian+++",
                        "    ⌋ ⌊     "
                },
                //Monkey 2
                {
                        " ʕ(▀ ⍡ ▀)ʔ  ",       //[2][0]
                        "  \\_⎐_/    ",
                        " <-ellen-> ",
                        "   〈  〉    "
                },
                //Monkey 3
                {
                        "ʕ ͡° ͜ʖ ° ͡ʔ  ",        //[3][0]
                        "  \\_⍾_/   ",
                        "==jazair== ",
                        "  _/ \\_   "
                },
                //Monkey 4
                {
                        "  (◕‿◕✿)    ",          //[4][0]
                        "  \\_⍾_/    ",          //[4][1]
                        "==mr.m== ",          //[4][2]
                        "  _/ \\_    "           //[4][3]
                },

        };
    }


    public void printPoem() {

        System.out.println();
        System.out.println("Monkey Jumpers Poem in Java Loopy");

        int monkeyCount = monkeys.length;
        for (int i = monkeyCount; i >= 1; i--) 
        {
            for (int col = 0; col < monkeys[col].length; col++) {  
                                                                    
             
                for (int row = 0; row < monkeyCount; row++) {    

                    
                    System.out.print(monkeys[row][col]); //print rows then columns instead of opposite

                    
                    System.out.print("\t"); //insert tab in text to line up each monkey in row
                    
                }

                System.out.println();
            }

            if (i > 1){
                System.out.println(i + " little monkeys jumping on the bed...");
            }
            else{
                System.out.println(i + " little monkey jumping on the bed...");
            }
            
            System.out.println("One fell down and bumped his head!");
            System.out.println("Mama called the doctor and the doctor said:");
            if (i == 1){   // if there is one monkey left, print the last line
                System.out.println("Put those monkeys right to bed!");
            }
            else{
                System.out.println("No more monkey's jumping on the bed!");
            }
            System.out.println();

            monkeyCount -= 1;
        }

        System.out.println("All the monkeys stopped jumping");
        System.out.println("Bye-bye monkeys");
    }

    public static void main(String[] args)  {
        new MonkeyLoop().printPoem();   
    }

}
MonkeyLoop.main(null);
Monkey Jumpers Poem in Java Loopy
ʕง ͠° ͟ل͜ ͡°)ʔ 	 ʕ༼ ◕_◕ ༽ʔ  	 ʕ(▀ ⍡ ▀)ʔ  	ʕ ͡° ͜ʖ ° ͡ʔ  	  (◕‿◕✿)    	
  \_⏄_/   	  \_⎏_/    	  \_⎐_/    	  \_⍾_/   	  \_⍾_/    	
---hetvi--  	 +++brian+++	 <-ellen-> 	==jazair== 	==mr.m== 	
   ⎛   ⎞    	    ⌋ ⌊     	   〈  〉    	  _/ \_   	  _/ \_    	
5 little monkeys jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more monkey's jumping on the bed!

ʕง ͠° ͟ل͜ ͡°)ʔ 	 ʕ༼ ◕_◕ ༽ʔ  	 ʕ(▀ ⍡ ▀)ʔ  	ʕ ͡° ͜ʖ ° ͡ʔ  	
  \_⏄_/   	  \_⎏_/    	  \_⎐_/    	  \_⍾_/   	
---hetvi--  	 +++brian+++	 <-ellen-> 	==jazair== 	
   ⎛   ⎞    	    ⌋ ⌊     	   〈  〉    	  _/ \_   	
4 little monkeys jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more monkey's jumping on the bed!

ʕง ͠° ͟ل͜ ͡°)ʔ 	 ʕ༼ ◕_◕ ༽ʔ  	 ʕ(▀ ⍡ ▀)ʔ  	
  \_⏄_/   	  \_⎏_/    	  \_⎐_/    	
---hetvi--  	 +++brian+++	 <-ellen-> 	
   ⎛   ⎞    	    ⌋ ⌊     	   〈  〉    	
3 little monkeys jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more monkey's jumping on the bed!

ʕง ͠° ͟ل͜ ͡°)ʔ 	 ʕ༼ ◕_◕ ༽ʔ  	
  \_⏄_/   	  \_⎏_/    	
---hetvi--  	 +++brian+++	
   ⎛   ⎞    	    ⌋ ⌊     	
2 little monkeys jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
No more monkey's jumping on the bed!

ʕง ͠° ͟ل͜ ͡°)ʔ 	
  \_⏄_/   	
---hetvi--  	
   ⎛   ⎞    	
1 little monkey jumping on the bed...
One fell down and bumped his head!
Mama called the doctor and the doctor said:
Put those monkeys right to bed!

All the monkeys stopped jumping
Bye-bye monkeys

Hacks Questions

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

This is more Imperative Programming Style because it is not based on objects. Object based programming is more for data sets and manipulating them. Imperative programming is more similar to what we are doing here: coding for each monkey to resolve the problem -- it fell off the bed.

  • Are the monkeys objects?

No they 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];

Notes and Takeaways

  • 2D arrays are like tables; they have rows and columns for storing data

  • Teachers can use a 2-D array to store students' grades Accessing 2D Arrays: Use[first][second] where the first index is the desired row, and the second index is the the desired column

  • 2D arrays are indexed starting at 0