This assignment will provide you with practice with program decomposition, writing static methods, using parameters of primitive types, returning values from static methods, and calling static methods.
This assignment consists of two parts, and you will be turning in three different classes (one for part 1, two for part 2). You should email these thre files to your TA.
You will write a Java class called ThisHouse that must be saved into a file called ThisHouse.java. Your program should produce the following nursery rhyme as output:
This is the house that Jack built.
This is the malt
That lay in the house that Jack built.
This is the rat
That ate the malt
That lay in the house that Jack built.
This is the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
This is the dog
That worried the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
This is the cow with the crumpled horn
That tossed the dog
That worried the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
This is the maiden all forlorn
That milked the cow with the crumpled horn
That tossed the dog
That worried the cat
That killed the rat
That ate the malt
That lay in the house that Jack built.
The output is the first seven verses of the nursery rhyme ``This is the house that Jack built'' by Mother Goose. For brevity, we reduced the number of verses from the original eleven to seven. The original rhyme can be found here.
You should EXACTLY reproduce the format of this output. This includes having identical wording, spelling, spacing, punctuation, and capitalization. Please do not include any extra verses. You may include blank lines at the end of the output, if you like. You do not need to reproduce the horizontal lines surrounding the text, only the text itself.
One way to write this program would be to simply write a {\tt println} statement that outputs each line of the rhyme 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 rhyme and improving the code using static methods.
Any println statement in your program should not be in your main method. Instead, use static methods in this program. You should be using static methods to capture the structure of the rhyme. You should, for example, have a method for each of the seven verses of the rhyme to print that verse's entire contents. You can write additional methods as you see fit. You should use only one println statement for each distinct non-blank line of the rhyme. For example, the line "That lay in the house that Jack built" appears several times in the output, but you should have only one println statement in your program that prints that line of the rhyme.
For this part, please write two Java files, one called Server.java and one called Client.java.
Server.java will contain just five public static methods:
/** Return the greatest common divisor of a and b. We assume that a and b are not 0. */ public static int gcd(int a, int b); /** Return the largest common proper prime factor of a and b (i.e. the factor is prime and not equal to a or b) */ public static int maxFactor(int a, int b); /** It prints out the first n Fibonaci numbers, where Fibonaci numbers are defined by F(0) = 1, F(1) = 1, F(k+2) = F(k+1)+F(k), for k = 0, 1, .. */ public static void fibonaci(int n); /** Given a number a > 1, Returns a number n such that for some m > 1 we have a = n ^ m. If no such n exists it returns 0, */ public static int aPower(int a); /** Given a number n > 0, Returns a number m such that n = 2^m. If no such m exists it returns -1, */ public static int aPowerOf2(int n);
Client.java will contain just the main method. In this method you will call the methods of the Server class to verify that they work properly. For example you may test gcd and maxFactor with arguments set one time to 48 and 30, another time to -48 and 15, another time to 48 and -21, another time to -48 and -23. You may test aPower nd aPowerOf2 by indicating for all numbers from 1 to 100 if they are a power and/or a power of 2. You may test fibonaci by executing fibonaci(16).