The goal of this lab is to write simple two simple classes using method calls to either System.out.print/println or those defined inside the classes. The two classes are HelloWorldPlus and class OldMcDonald and the score breakdown is 50-50 between the two.
Part (a) Hello World Plus
Write a class HelloWorldPlus that produces three lines of output as follows:
% java HelloWorldPlus
Hello, World!
My name is XXX.
My favorite word is “YYY”.
Note that the first line % java HelloWorldPlus
is the command for executing the code.
Here XXX and YYY are placeholders and up to your choice. The main method of this class has three System.out.println statements, which are respectively responsible for the three lines of output. The word YYY should be printed with double quotation marks surrounding it. Note that to include a double quotation mark in the character sequence to be printed in the System.out.println (or print) you need to put a backslash in front of it. For example, to print
My favorite word is “endurance”.
with a newline, you need to use
System.out.println( "My favorite word is \"endurance\"." );
Part (b) Old McDonald
Write a class OldMcDonald that produces three verses of a children's rhyme Old McDonald Had a Farm as follows:
As you can see there shall be one empty line should be printed the last “... E-I-E-I-O” line of each verse.
We will assign a single or pair of lines a specific role as follows:
We treat these eight modules as individual methods:
Then the main method shall be:
public static void main( String[] args ) {
verseOne();
verseTwo();
verseThree();
}
Your task is to complete the template given to you. For the methods numbered 1 - 5, the body of the method is a single System.out.println statement; for the methods numbered 6 - 8, the body of the method is two System.out.println statements. For the methods numbered 9 - 11, they are built using method calls. The first verse (method number 9) is already coded (and some other methods, too), and you can use its construction to come up with how to write the other two verses.
Here is a template: OldMcDonald.java