Introduction to Programming (CPSC 124)
—Hobart & William Smith Colleges, Fall 2014
Project #1
Home | Syllabus | Calendar | Class Notes | Labs and Projects | General Notes

Due by the start of class on Thursday, 09/11/2014

Overview

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).

Your job

  1. 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.

    Example interactions:

    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

  2. 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".

    Example interaction:

    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)

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