Question

In: Computer Science

5.6.2.  Programming Challenge : Song with Parameters Here’s another song, The Ants Go Marching, that is very...

5.6.2.  Programming Challenge : Song with Parameters

Here’s another song, The Ants Go Marching, that is very similar to the This Old Man song in its repetitive structure.

 The ants go marching one by one, hurrah, hurrah
 The ants go marching one by one, hurrah, hurrah
 The ants go marching one by one
 The little one stops to suck his thumb
 And they all go marching down to the ground

 The ants go marching two by two, hurrah, hurrah
 The ants go marching two by two, hurrah, hurrah
 The ants go marching two by two
 The little one stops to tie his shoe
 And they all go marching down to the ground

 The ants go marching three by three, hurrah, hurrah
 The ants go marching three by three, hurrah, hurrah
 The ants go marching three by three
 The little one stops to climb a tree
 And they all go marching down to the ground
 
  1. Print out the The Ants Go Marching song and circle the repeated parts of the song.

  2. In the active code window below, create a method or methods that takes parameters to print out a verse. The method(s) should be abstract enough to work for all 3 verses. Use good commenting for your methods that describe the @param. For the autograder, make sure you create a method called verse that takes 2 parameters.

  3. In the main method, create an object of the class and call the method(s) you created in the last step to print out 3 verses of the song. Can you add more verses?

Create method(s) with parameters to print out verses of the song The Ants Go Marching. https://www.lyrics.com/lyric/5526512/The+Ants+Go+Marching

public class Song
{
// Create at least 1 method called verse that takes 2 parameters
// that can be used to print out the verses of the song The Ants Go Marching


public static void main(String args[])
{
// Create a Song object and call its method(s) to print out
// the verses of The Ants Go Marching
// There should be atleast 1 method called verse that takes 2 arguments.


}
}

Solutions

Expert Solution

Please find below the code, code screenshots and output screenshots. Please refer to the screenshot of the code to understand the indentation of the code.  Please get back to me if you need any change in code. Else please upvote

CODE:

public class Song

{

    /**

     * Sings the first two lines.

     *

     * @param number (as a word) for how the ants march

     */

    public static void goMarching(String number)

    {

         System.out.println("The ants go marching " + number + " by " + number + ", hurrah, hurrah");

    }

   

    /**

     * Sings the third line.

     *

     * @param number (as a word) for how the ants march

     */

    public static void noHurrah(String number)

    {

        System.out.println("The ants go marching " + number + " by " + number);

    }

   

    /**

     * Sings the 4th line about the little ant.

     *

     * @param action What the little one stops to do

     */

    public static void littleAnt(String action)

    {

        System.out.println("The little one stops to " + action);

    }

   

    /**

     * Sings the last line of each verse.

     */

    public static void rain()

    {

        System.out.println("And they all go marching down to the ground\n");

    }

    /**

     * Sings a verse of Ants Go Marching.

     *

     * @param n(as a word) for how the ants march

     * @param action What the little one stops to do

     */

   public static void verse(String n, String action)

    {

        goMarching(n);

        goMarching(n);

        noHurrah(n);

        littleAnt(action);

        rain();

    }

   

    /**

     * Calls the verse() for each verse.

     */

    public static void main(String[] args)

    {

        verse("one","suck his thumb");

        verse("two","tie his shoe");

        verse("three","climb a tree");

        verse("four","shut the door");

        verse("five","take a dive");

        verse("six","pick up sticks");

        verse("seven","pray to heaven");

        verse("eight","roller skate");

        verse("nine","check the time");

        verse("ten","shout THE END!");

    }

  

}

OUTPUT:


Related Solutions

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT