CSE142—Computer Programming I

Programming Assignment #1

Due: Tuesday, April 7, 2009, 9 pm

Your first program will require static methods and println statements.  This assignment is worth 10 points instead of the normal 20 points.  You will write a Java program that produces as output a cumulative song in which successive verses build on previous verses (as described in http://en.wikipedia.org/wiki/Cumulative_song).  Your program should produce as output the following song:

There was an old woman who swallowed a fly.

I don't know why she swallowed that fly,

Perhaps she'll die.

 

There was an old woman who swallowed a spider,

That wriggled and iggled and jiggled inside her.

She swallowed the spider to catch the fly,

I don't know why she swallowed that fly,

Perhaps she'll die.

 

There was an old woman who swallowed a bird,

How absurd to swallow a bird.

She swallowed the bird to catch the spider,

She swallowed the spider to catch the fly,

I don't know why she swallowed that fly,

Perhaps she'll die.

 

There was an old woman who swallowed a cat,

Imagine that to swallow a cat.

She swallowed the cat to catch the bird,

She swallowed the bird to catch the spider,

She swallowed the spider to catch the fly,

I don't know why she swallowed that fly,

Perhaps she'll die.

 

There was an old woman who swallowed a dog,

What a hog to swallow a dog.

She swallowed the dog to catch the cat,

She swallowed the cat to catch the bird,

She swallowed the bird to catch the spider,

She swallowed the spider to catch the fly,

I don't know why she swallowed that fly,

Perhaps she'll die.

 

<< Your custom sixth verse goes here >>

 

There was an old woman who swallowed a horse,

She died of course.

As indicated above, you should include a custom sixth verse that matches the pattern of the first five verses.  You must exactly reproduce the format of this output.

Most of our assignments will have a creative aspect where you have more flexibility than normal to come up with your own solution.  For this assignment, it involves writing a sixth verse that fits the pattern of the first five.  For example, some versions of the song have a sixth verse for swallowing a goat (ÒJust opened her throat to swallow a goatÓ).  Notice that the first two lines should either end in the same word (fly/fly, bird/bird, cat/cat, etc) or in rhyming words (spider/inside her).  You are not allowed to simply copy one of the previous animals or to use verses you find on the web (e.g., goat and cow).  You have to write your own verse.  The text of the verse should not include hateful, offensive, or otherwise inappropriate speech.

You should use static methods to avoid redundancy.  In particular, you should make sure that you use only one println statement for each distinct line of the song.  For example, this line:

Perhaps she'll die.

appears several times in the output.  You should have only one println statement in your program for producing this line. 

There is a structural redundancy that you can eliminate with static methods and this will be worth one point.  The key question to ask yourself is whether or not you have repeated lines of code that could be eliminated if you structured your static methods differently.  Hint: any method (not just 'main') can call another method to perform part of its work.

 You should not try to remove redundancy related to different lines having similar text, such as:

There was an old woman who swallowed a horse,

There was an old woman who swallowed a dog,

and:

She swallowed the dog to eat the cat,

She swallowed the cat to eat the bird,

It is not possible to avoid the redundancy from repeating, for example, ÒThere was anÓ or, ÒShe swallowed theÓ using just methods and println statements, so you are not expected to do so. 

You should also be using static methods to capture the structure of the song.  You must, for example, have a method for each of the seven verses of the song (verses are separated by blank lines in the output).

You are not allowed to use more advanced features than what we have covered in class.  For this assignment, you should limit yourself to the Java features covered in Chapter 1 of the text.

You should include a comment at the beginning of your program with some basic information and a description of the program, as in:

// Bruce Wayne

// 1/12/09

// CSE142

// TA: Clark Kent

// Assignment #1

//

// This program will...

You should name your file Song.java and you should turn it in electronically from the ÒassignmentsÓ link on the class web page.