Due by the start of class on Thursday, 09/11/2014
The goal of this assignment is to give you some more concrete practice with whole program construction and with the use of the args parameter in your program's "main" section to read command line arguments. You'll write two programs in the style of the first ones we saw (see the Class Notes from 09/03/2014).
Write a program called HappyBirthday. This program is run with a single argument, representing someone's name. The program should print a nicely formatted version of the "Happy Birthday" song, addressed to that person.
John-Lasseter:~ jlasseter$ java HappyBirthday Wolfgang Happy birthday to you! Happy birthday to you! Happy birthday, dear Wolfgang! Happy birthday to you you! John-Lasseter:~ jlasseter$ java HappyBirthday LouisXIV Happy birthday to you! Happy birthday to you! Happy birthday, dear LouisXIV! Happy birthday to you you!
As you can see from the example, this work should be saved in a file called HappyBirthday.java
Write a program that, given the name of an animal and a sound as arguments, will print a verse from the song"Old MacDonald Had a Farm".
John-Lasseter:~ jlasseter$ java Farm chicken bawk Well, Old MacDonald had a farm. E-I-E-I-O. And on this farm, he had a chicken. E-I-E-I-O. With a "bawk-bawk" here and a "bawk-bawk" there, Here "bawk", there "bawk", everywhere "bawk-bawk". Old MacDonald had a farm. E-I-E-I-O. John-Lasseter:~ jlasseter$ java Farm pig gron Well, Old MacDonald had a farm. E-I-E-I-O. And on this farm, he had a pig. E-I-E-I-O. With a "gron-gron" here and a "gron-gron" there, Here "gron", there "gron", everywhere "gron-gron". Old MacDonald had a farm. E-I-E-I-O.
The source file for this program should be called Farm.java
About the quotation marks
It's kind of tricky to print quote marks in the System.out.println() statements, since you cannot just use " directly, as that symbol is used to delineate the parts of the string to print out. For example, the attempt to print out the opening line of Mody Dick
"Call me Ishmael." Herman Melville: Moby-Dick (1851)
using the statements
System.out.println(""Call me Ishmael.""); System.out.println("Herman Melville: Moby-Dick (1851))"
will result in a compiler error.
To actually print the " character, you need to escape the normal rules for strings, by using \" instead, whenever you want the actual " character to print:
System.out.println("\"Call me Ishmael.\""); System.out.println("Herman Melville: Moby-Dick (1851))"
Put those two lines in a little program and try it out!
Standards (READ ME)
Your code for both programs must be syntactically and semantically correct, which means that it has to compile successfully.
I cannot emphasize this enough. Any solution that cannot be successfully compiled with javac will receive no credit. If you run into any trouble here, please ask me for help, which I am always happy to give (as are the TAs). I know this seems draconian, but I promise you'll thank me for it later.
Naturally, your code for both programs must also be behaviorally correct, which means that it should print the right output in the right format. However, partial credit will be given for partial solutions. At a minimum, be sure to test on the examples you planned beforehand.
Turn in (READ ME):
You are to submit both your source code files electronically and with a printed copy (I need to have paper to mark up and the digital file to run your program). Your source files should be saved in a folder named hw1 and this folder should be copied copied into your folder in the class directory
/classes/cs124/<your user name>/
NOTE: Make sure you're actually copying it to this folder and not your own home folder at /afs/afs.hws.edu/home/<your user name>! This is an obvious source of confusion, and will lead you to think you've turned in your work to me when you haven't.
Also, please respect my file name requests. I ask for precise names because it makes it easier for me to test your work. Thanks.
John H. E. Lasseter