Code reuse: Simple methods in Java
30 points
Due on Blackboard by 11:59:59pm Friday, April 9

Get started early and finish early!

Assignment Purpose:

This assignment will get you to think critically about code reuse via methods.  It requires problem solving to minimize the code (especially the first exercise), thus this assignment gives you practice in this area as well.


15 points

Implement problem 10 on page 49 of your text, which says:

Write a program that prints the following line of output 1000 times

All play and no work makes Jack an unemployed boy.

You should not write a program whose source code is 1000 lines long; use methods to shorten the program.  What is the shortest program you can write that will produce the 1000 lines of output, using ONLY the material from chapter 1 (meaning no loops or recursion is allowed)?  For the intents and purposes of counting, the class declaration and any {} combination do not count as lines of code -- everything else does (method definitions and statements inside each method).  Include the answer at the top of your source code in a comment.  HINT: First try and figure out the minimum lines for a smaller number like 10, then work your way up.  NOTE: You must come up with a solution that is no more than 30 lines of code.

Name your source file

15 points

Implement problem 3 on Page 50 of your text, which says:

"Write a program that produces as output the lyrics of the song, 'There Was an Old Lady.'  Use methods for each verse and the refrain.  Here are the song's initial lyrics:

There was an old lady who swallowed a fly.
I don't know why she swallowed that fly,
Perhaps she'll die.

There was an old lady 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.

etc. "

Additional Details


Submit to blackboard a .zip file that contains your Java source files ( and and the .class files produced from compilation (ThereWasAnOldLady.class and Jack1000.class). 

Include comments at the top of each source file that contains your name and a description of the program.  List any issues the program has.  Make sure your code adheres to the naming conventions we have discussed in class.

Also include a capture of the output produced from running your programs.  This output should be placed in a text file named ThereWasAnOldLady.txt, and Jack100.txt, respectively.  Name your zip with your last name, followed by the first initial of your first name, followed by hw1 (ex: