Even with our extremely limited Java skillset in this first week of class,
we are still able to exercise some of the fundamentals of computational
thinking. One of those fundamentals we'll explore in this homework is the
ability to identify structure within a problem that we're trying to solve
and then eliminate redundancy in the code we make to solve that problem.
Problem
A cumulative
song is song whose verses build upon each other. Classic examples of
cumulative songs include "There was an Old Lady that Swallowed a Fly" and "The
Twelve Days of Christmas". For this homework, you will be reproducing the
lyrics of a more contemporary cumulative song: the "Song of Love" from the
Broadway musical comedy
Once Upon a
Mattress.
For reference, here's the Song of Love performed by the Bakersfield Theatre
of Bakersfield, California:
I like you, Fred, I like you!
You're just saying those words to be kind.
No, I mean it. I like... I mean I love you, Fred!
He is out of his medieval mind!
I'm perfectly sane and sound! I never felt better in my life!
Everybody... everybody, everybody! Come on! And meet my incipient wife!
I'm in love with a girl named Fred.
My reasons must be clear.
When she shows you all how strong she is you'll stand right up and cheer!
With a "F" and a "R" and an "E" and a "D"
And a "F-R-E-D" Fred! Yeah!
I'm in love with a girl named Fred.
She drinks just like a lord!
So sing a merry drinking song and let the wine be poured!
Fill the bowl to overflowing. Raise the goblet high!
With a "F" and a "R" and an "E" and a "D"
And a "F-R-E-D" Fred! Yeah!
I'm in love with a girl named Fred.
She sings just like a bird!
You'll be left completely speechless when her gentle voice is heard!
La la la la, la la la la, la la la la la!
Fill the bowl to overflowing. Raise the goblet high!
With a "F" and a "R" and an "E" and a "D"
And a "F-R-E-D" Fred! Yeah!
I'm in love with a girl named Fred.
She wrestles like a Greek!
You will clap your hands in wonder at her fabulous technique!
Clap clap, clap clap, clap clap clap clap, clap, clap clap!
La la la la, la la la la, la la la la la!
Fill the bowl to overflowing. Raise the goblet high!
With a "F" and a "R" and an "E" and a "D"
And a "F-R-E-D" Fred! Yeah!
I'm in love with a girl named Fred.
She dances with such grace!
You are bound to sing her praises 'til you're purple in the face!
Bravo! Bravo! Bravissimo bravo! Bravissimo!
Clap clap, clap clap, clap clap clap clap, clap, clap clap!
La la la la, la la la la, la la la la la!
Fill the bowl to overflowing. Raise the goblet high!
With a "F" and a "R" and an "E" and a "D"
And a "F-R-E-D" Fred! Yeah!
I'm in love with a girl named Fred.
She's musical to boot!
She will set your feet a-tapping when she plays upon her lute!
Strum strum, strum strum, strum strum strum strum strum, strum.
Bravo! Bravo! Bravissimo bravo! Bravissimo!
Clap clap, clap clap, clap clap clap clap, clap, clap clap!
La la la la, la la la la, la la la la la!
Fill the bowl to overflowing. Raise the goblet high!
With a "F" and a "R" and an "E" and a "D"
And a "F-R-E-D" Fred! Yeah!
I'm in love with a girl named Fred.
A clever, clownish wit!
When she does her funny pantomime your sides are sure to split!
Ha ha ha ha, ho ho ho ho, ha ha ha ha ho!
Strum strum, strum strum, strum strum strum strum strum, strum.
Bravo! Bravo! Bravissimo bravo! Bravissimo!
Clap clap, clap clap, clap clap clap clap, clap, clap clap!
La la la la, la la la la, la la la la la!
Fill the bowl to overflowing. Raise the goblet high!
With a "F" and a "R" and an "E" and a "D"
And a "F-R-E-D" Fred! Yeah!
I'm in love with a girl.
He's in love with a girl named "F-R-E-D" Fred!
Your goal is to write a program to reproduce exactly the lyrics to
the Song of Love as presented above. You should preserve capitalization,
punctation, and spacing. As a rule of thumb, a computer will do exactly
what you tell it and no better (or worse), so you will need to be dilligent
about checking the output of your program to ensure that it matches the format
above.
Your program should exist in a Java class called SongOfLove contained in a
file called SongOfLove.java. You must use this exact file and class name and
remember, capitalization matters!
Style
One easy way to do this program is to copy-paste the above lyrics into your
Java file and wrap it in System.out.println(...) calls. However, this defeats
the purpose of the assignment. Instead you should use static methods to both
capture the structure of the song and eliminate redundancy of your
code.
Capturing structure
As much as possible, your programs should capture the inherent structure of
the problem at hand. In this case, your program should reflect the fact that a
song can be decomposed into a series of verses. For example, you should have a
static method for each verse that prints the contents of that verse to the
console.
Eliminating redundancy
If you inspect the lyrics, you'll quickly notice that several lines are
repeated, for example, the line
I'm in love with a girl named Fred
appears in every verse beyond the first and last. While we could write one
println for each time we print this line to the console, imagine if we made a
typo transcribing the line. We would need to visit each of the printlns to
ensure that we didn't make the same mistake at each, a code maintenance disaster
even by our simple standards!
However, simply factoring out that line into its own method is not enough.
You must identify whole groups of lines that are repeated in the song and
use static methods to eliminate those redundancies. Keep in mind that static
methods can call other static methods. So you'll need to take a step back and
figure out how reduce redundancy not only in groups of repeated println
statements but also groups of repeated static method calls as well.
You should concern yourself with redundancy whole lines of printlns versus
within lines themselves. For example, in the line "Clap clap, clap clap, clap
clap clap clap, clap, clap clap!", you do not need to worry about creating a
static method that System.out.print's (which prints to the console without
adding a line break) that prints individual claps to the console. You can treat
the line as a single chunk.
Other important things
Please include a comment at the beginning of your program that includes your
name, email, section, and your own (short) description of what the program does,
for example:
// Ada Lovelace, ada@lovelace.com
// CIS 110 (section 005) - Homework 1
// <One-to-two sentence description of what the program does>
Please follow the style guide when writing
your code. Good coding style is a habit that you need to practice from the
beginning. To encourage this, 1-2 points of your overall grade on each
assignment will be dedicated to following the style guide exactly, so make sure
you do what it says!
For this first assignment please only use the elements of Java found in
Chapter 1 of the textbook. You won't need to use anything more complicated than
static methods and printlns to finish this homework.
Submission
Please submit
your Java source file, SongOfLove.java, electronically via the
course website.