CS312 Song Assignment CS 312 Assignment - Problem Decomposition - static methods and printlns 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. 10 points, ~1% of total grade Due: no later than 11 pm, Thursday, September 10 General Assignment Requirements Description: The purposes of this assignment are: To create a program to produce required output. To practice creating structured programs To practice removing redundancy from programs. To learn the procedures and tools for writing an submitting programs. Complete the items on the class start up page. If you get stuck post to the class discussion group on Piazza or go see the instructor or a TA in help hours. I strongly recommend downloading the given shell file, Song.java, and using it in whatever IDE you have chosen to use in CS312. Complete a Java program named Song,java that when produces the following output when run, the lyrics of the song There Was an Old Woman Who Swallowed a Fly. Here is the program shell to start with. 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. Here is the output file the graders will use on assignment 1.(A1_Song_Output.txt) Your output must match this exactly or you may lose points for correctness. Use a diff tool such as the one at this website (www.diffchecker.com) to ensure your program produces the correct output. Please note, if you view the output above via a web browser, the browser will very likely remove the last newline character. This causes a minor difference between the expected output and your output. Note, we will typically ignore newline characters when comparing your output and the expected output. The last line of the song, "She died of course.", is printed out with a println statement, just like all the other lines of the song. I recommend you download the A1_Song_Output.txt file by putting your cursor over the link and bringing up a context menu (right click on Windows, control click on Macs) and select the option to download the file. If you simply open the text file in a web browser, the browser removes blank lines at the end of the file. You may only use static methods and println statements. Do not use print statements in your program. (or variables, parameters, loops, conditional statements, recursion, etc.) Static methods, static method calls, and println statements only. Use static methods to capture the structure of the song. You should, for example, have a different method for each of the eight verses of the song (verses are separated by blank lines in the output). Make use of static methods to avoid 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. On the other hand, for CS312 assignment 1, do not make methods with a single println statement and no other statements or method calls. Methods such as those take program decomposition too far. It is likely you will have methods with a single println statement in addition to other method calls or statements. In other words this is bad: public static void someMethod() { System.out.println("SOME STUFF"); } but this is okay and necessary in some cases: public static void someMethod() { System.out.println("SOME STUFF"); callAnotherMethod(); } 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 somewhere in your program or the line There was an old woman who swallowed a horse, and another println, somewhere else in your program, 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. For this assignment, you shall limit yourself to the static methods and println statements. Do not use print statements or other Java language features. Submission: Turn in your Song.java file with your code Canvas. If you do not turn in the correct file with the correct name you will very likely end up wasting slip days or getting a 0 on the assignment. See this page for instructions to turn in a file for an assignment via Canvas. Your submission must be named Song.java and your program name (class name) must be Song. Note, you may turn in the file multiple times via Canvas. Canvas adds a "-1" to the file name. So if you turn in your program a second time before the due date the file name will be something like Song-1.java. That is fine. Our grading scripts will adjust for the extra cruft Canvas adds to the file name. Checklist: Did you remember to: review the general assignment requirements? work on the assignment individually? fill in the header in your file Song.java program including replacing with your name stating the work you are turning in is your own and fill in the header? make your program structured and remove redundancy? ensure your program does not suffer a compile error or runtime error? ensure your program matches the expected output exactly? ensure your program is part of the default package? In other words there are no package statements in your program. turn in your Java source code in a file named Song.java via Canvas before 11 pm, Thursday, September 10? Thanks to Stuart Reges for sharing this assignment with me. Back to the CS 312 homepage.