CS 312 Assignment - Problem Decomposition

Programming Assignment 1: Individual Assignment. You must complete this assignment by yourself. You cannot work with anyone else in the class or with someone outside of the class. The code your write must be your own. You are encouraged to get help from the instructional staff.

Placed online: Friday, January 11
10 points, ~1% of total grade
Due: no later than 11 pm, Friday, January 25
General Assignment Requirements

Description: The purposes of this assignment are:

  1. To create a program to produce required output.
  2. To practice creating structured programs
  3. To practice removing redundancy from programs.

Steps to Complete Assignment: (If you get stuck post to the class discussion group on Piazza or go see the instructor, TA, or proctor in lab hours.)

  1. Go to https://apps.cs.utexas.edu/udb/newaccount/ to request a CS lab account. You must remember the account name and password you choose. ou must have this account to turn in your files, even if you do not plan on working in the lab.
     
  2. Sign up for the class discussion group on Piazza if you have not already signed up.
  3. (If you plan on working in the lab skip to step 5.)
    If you are planning on working at home during the semester download Java on to your computer by following the instructions on the class web page.
     
  4. If you are planning on working at home during the semester  and you want to use an interactive development environment to help you create and run Java programs I suggest you use BlueJ. See this page for links for downloading and running BlueJ.
     
  5. Create a new project and add the Song.java file. This page has instructions on how to create projects and add source code to BlueJ.
     
  6. Complete the required program as described below.
     
  7. Save your program! If you are working in the lab it is very important to do this. The microlab machines do not save your work! They delete it as soon as you log off. You may save your files using the turnin program , or transfer them onto a USB memory stick, or send them to yourself in email, or use webspace .

Complete a Java program (here is the program shell to start with) that when run produces the following output (The lyrics of the song There Was an Old Woman Who Swallowed a Fly):

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.

There was an old woman who swallowed a goat,
She just opened her throat to swallow a goat.
She swallowed the goat to catch the 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 cow,
I don't know how she swallowed a cow.
She swallowed the cow to catch the goat,
She swallowed the goat to catch the 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.

Your program must match the output shown above exactly.

You are to make use of static methods to avoid “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.  So you may have static methods with a single println in them.

There is a more complex redundancy that comes up 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. 

In other words the lines

    There was an old woman who swallowed a horse,
  There was an old woman who swallowed a dog,

are very similar. The only difference is the last word. It is okay to have one println for the line

    There was an old woman who swallowed a horse,

and another println for the line

    There was an old woman who swallowed a dog,

even though it seems redundant.

There is, however, a structural redundancy that you can eliminate with static methods.  The key question to ask yourself is whether or not you have repeated lines of code or statements that could be eliminated if you structured your static methods differently. These lines of codes could be calls to static methods instead of println statements.

Use static methods to capture the structure of the song.  You should, for example, have a different method for each of the six 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 shall limit yourself to the Java features covered in chapter 1 of the text.

Submission: Turn in your Song.java file with your code using the turnin program. Ensure you turn in the correct, changed file to the correct location! If you do not turn in the correct file you will very likely end up wasting slip days or getting a 0 on the assignment.


Here is a shell of the program. Be sure to fill in the header. Replace <Name> with your name and fill in the required information.

Checklist: Did you remember to:

 Thanks to Stuart Reges for letting me use this assignment.

Back to the CS 312 homepage.