handout #5

CSE142—Computer Programming I

Programming Assignment #1

due: Wednesday, 10/6/04, 9 pm

Your first program will require the use of static methods and println statements.  This is assignment is worth 10 points instead of the normal 20 points.  You are going to write a Java program that produces 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 insider 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.

 

There was an old woman who swallowed a horse,

She died of course.

You must exactly reproduce the format of this output, although you are allowed to have an extra blank line after the “She died” line if it makes your program easier to write.

You are to make use of static methods to avoid the "simple" redundancy.  In particular, you are to 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 are to have only one println statement in your program for producing this line.  The more complex redundancy has to do with pairs of lines like these

There was an old woman who swallowed a horse,

There was an old woman who swallowed a dog,

and like these

She swallowed the dog to eat the cat,

She swallowed the cat to eat the bird,

It is not possible to avoid this redundancy using just methods and simple 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 should, for example, have a different method for each verse of the song.

You should include a comment at the beginning of your program with some basic

information and a description of the program, as in:

// Stuart Reges

// 10/1/04

// CSE142

// TA:  George Bush

// Assignment #1

//

// This program will...

You should name your file Song.java and you should turn it in electronically.  There will be instructions linked from the “assignments” link on the class web page.