Singing the Bingo Song

As we have seen several times this semester, computers are good at performing repetitive tasks, and it is in a programmer’s best interest to try to find the patterns that best capture the repetition involved. Loop statements are one way to capture such patterns; methods are another that we will see soon.

One place that many people encounter patterns is in the verses of rounds and other repetitive song forms. These kinds of songs are very common, especially with younger children who are both learning how to sing and how to understand patterns. In this lab (and one more later on) we will explore how to capture the patterns of some simple songs in Java code.

Our song for this time around will be the childhood favorite about a dog named Bingo: if you haven’t heard this song before, don’t worry, here are the lyrics:


There was a farmer, had a dog, and Bingo was his name-o ...

	B I N G O ,
	B I N G O ,
	B I N G O ,

and Bingo was his name-o.


There was a farmer, had a dog, and Bingo was his name-o ...

	_ I N G O ,
	_ I N G O ,
	_ I N G O ,

and Bingo was his name-o.


There was a farmer, had a dog, and Bingo was his name-o ...

	_ _ N G O ,
	_ _ N G O ,
	_ _ N G O ,

and Bingo was his name-o.


There was a farmer, had a dog, and Bingo was his name-o ...

	_ _ _ G O ,
	_ _ _ G O ,
	_ _ _ G O ,

and Bingo was his name-o.


There was a farmer, had a dog, and Bingo was his name-o ...

	_ _ _ _ O ,
	_ _ _ _ O ,
	_ _ _ _ O ,

and Bingo was his name-o.


There was a farmer, had a dog, and Bingo was his name-o ...

	_ _ _ _ _ ,
	_ _ _ _ _ ,
	_ _ _ _ _ ,

and Bingo was his name-o.

(If you are not familiar with the tune itself, perhaps your instructor and class-mates can sing it for you in lecture!)

In the lyrics printed above, the underscores ( _ ) are meant to be “clapped” rather than actually sung, in a rhythm that fits in with the song, but interrupts the sung words. With each verse, one of the letters of the dog’s name is replaced in the chorus, until the entire name is clapped rather than sung.

Singing Bingo with code

We can take advantage of a computer to perform the repetitive task of writing out the lyrics to the Bingo song.

(Well, not really the lyrics to just that song: that would be silly, since we have them right here on the screen in front of us! The idea, rather, is to write a program which could reproduce this very same structure of song, but with any dog’s name in place of Bingo; i.e., Spot or Snoopy or even Marmaduke.)

Look at the lyrics above again: they have a very regular structure, one which could easily be reflected in a program using nested loops. The outer loop would run through the several verses of the song, as many as there are letters in the dog’s name, plus one for the extra time around at the beginning (the one with no claps). Inside this would come some code to print the introductory and closing parts (“There was a farmer ...” and “and Bingo was his name-o”), but in between these two would come another loop, This loop would run exactly three times around, always, in order to get the repetition of the “inner chorus” (this may not be an accurate musical term). And finally, there would be an innermost loop, running for as many times around as there are letters in the name (5 for Bingo), which would sometimes print letters and sometimes print “claps”, depending on ... well, what? (Hint: it has to do with which outer-loop verse we are on!)

The final structure would look something like this, at least as far as the nested loops are concerned (there would of course also be code for the class, a scanner to read in a dog’s name, the main method declaration, various braces, etc.):


...

	for( outer loop, per # of letters + 1 )
	{
		intro text
		
		for ( middle loop, always 3 times)
		{
			for ( inner loop, per # of letters )
			{
				clapping name chorus
			}
		}
		
		"outro" text
	}
...

Your assignment

To complete this assignment, you should write a program which will read in the name of a dog from the user, and sing a “Bingo-like song” about it. That is, the song should have the same general structure as the one above, but with the name Bingo replaced by the actual name the user types in.

In particular, your song should have:

You should turn in print-outs containing: