Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please read the style guide line (the program in JAVA) Description This program tests your understanding of using static methods and println statements. You should
Please read the style guide line (the program in JAVA)
Description This program tests your understanding of using static methods and println statements. You should write a Java class called song that should be saved into a file called song.java. The program should produce as output the following song, which is a shortened version of a classic American folk song named, Bought Me a Cat. Bought me a cat and the cat pleased me, I fed my cat under yonder tree Cat goes fiddle-i-fee Bought me a hen and the hen pleased me, I fed my hen under yonder tree Hen goes chimmy-chuck, chimmy-chuck Cat goes fiddle-i-fee Bought me a duck and the duck pleased me, I fed my duck under yonder tree. Duck goes quack, quack, Hen goes chimmy-chuck, chimmy-chuck Cat goes fiddle-i-fee Bought me a goose and the goose pleased me, I fed my goose under yonder tree. Goo se goes hissy, hissy, Duck goes quack, quack, Hen goes chimmy-chuck, chimmy-chuck Cat goes fiddle-i-fee Bought me a sheep and the sheep pleased me, I fed my sheep under yonder tree. Sheep goes baa, baa, Goo se goes hissy, hissy, Duck goes quack, quack, Hen goes chimmy-chuck, chimmy-chuck Cat goes fiddle-i-fee Bought me a pig and the pig pleased me, I fed my pig under yonder tree Pig goes oink, oink, Sheep goes baa, baa, Goose goes hissy, hissy, Duck goes quack, quack, Hen goes chimmy-chuck, chimmy-chuck, Cat goes fiddle-i-fee. The first five verses of the song (all except the final bolded "pig" verse above) must exactly reproduce the output shown above. This includes having identical wording, spelling, spacing, punctuation, and capitalization Stylistic Guidelines One way to write this program would be to simply write a println statement that outputs each line of the song in order. However, such a solution would not receive full credit. Part of the challenge of this assignment lies in recognizing the structure and redundancy of the song and improving the code using static methods You should not place any println statements in your main method. (It is okay for main to have empty println statements to print blank lines.) Instead of printing in main, use static methods for two reasons 1. To capture the structure of the song's six verses You should write static methods to capture the structure of the song. You should, for example, have a method for each of the six verses of the song to print that verse's entire contents 2. To avoid simple redundancy in the output You should use only one println statement for each distinct non-blank line of the song. For example, the following line appears several times in the output, but you should have only one println statement in your program that prints that line of the song Cat goes fiddle-i-fee However, a method that prints a single line such as the above is not useful. Instead, you should identify groups of two or more lines that appear in multiple places in the song and create static methods that capture those groups and are called multiple times. There is a general structural redundancy to the song that you should eliminate with your static methods. Recall that methods can call other methods if necessary. The key question to ask yourself is whether or not you have repeated lines of code that could be eliminated if you structured your static methods differently. As a point of reference, our solution to this program has twelve static methods other than main (only one of which prints a single line) and occupies 89 lines including comments and blank lines. (This does not mean that your solution is required to be the same length.) You do NOT have to eliminate redundancy in lines that are similar but not identical, such as these Bought me a cat and the cat pleased me Bought me a dog and the dog pleased me It is not possible to avoid this partial-line redundancy using just what we have learned so far (static methods and simple println statements), so you are not expected to eliminate itStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started