CS 1073 Introductory Programming
for Scientific Applications
Homework 4: Bottles of Beer


Due Date:


Overview: This homework asks you to write a Java program that will print the complete song Ninety-nine Bottles of Beer on the Ball:

This is the (familiar) song:

Here is the complete song. The numbers should be spelled out in English, and you must make use of several strings and arrays of strings, as well as making use of functions, all described below.


Strings to use: First here are several arrays of strings and several strings that you must use in finishing this homework:
Two functions to write: You should also write two functions that you call:

  1. First write a function (method) toEnglish that will convert its int input parameter (in the range from 0 to 99 inclusive) to English. [Hints: You must use the predefined arrays of Strings, and not try to write this method in the way that Project 1 was written. First handle an input parameter value n < 20 with the teens array. Remember, if the input parameter is n = 47 then n/10 will equal 4 and you can use the tens array. Similarly n%10 will equal 7 and you can use the ones array. Then concatenate.]

  2. Then write a method printSong() that will print the whole song. [Hints: Use a loop with a variable going from 99 down to 1. You must use a loop; you cannot suggest writing 99 segments of code.]

  3. As a final small problem, add code to get rid of the "s" on the end of "bottles" when you get to "One bottle of beer ...".


Non-static functions: You should write this Java program using all non-static functions, called methods (except for main) as illustrated in examples using non-static methods. in a more object-oriented style.


What to turn in:
  1. Source listings (the Java code) for the program.

  2. Truncated result of a run.

    Note: You should use netBeans, though it is permissible to use Java from another source. In netBeans, the simplest way to make up the material to print is to just copy from netBeans (using ctrl-C) and paste into Word or WordPad (using ctrl-V). Then print the resulting document. You can assemble all 5 programs into a single document to print.

    In case your program doesn't produce output or doesn't produce the correct output, you should still turn in a listing for part credit.