15-110 FALL 2009 [CORTINA]

LAB 0: Writing a Simple Java Program

The U.S. Post Office speeds its delivery of mail by the use of a postal bar code. Each digit of the 5-digit zip code is encoded using one of the 10 patterns shown below:

   Number   Bar code          Number    Bar code 
   -----------------          ------------------ 
     0       ||,,,              5        ,|,|, 
     1       ,,,||              6        ,||,, 
     2       ,,|,|              7        |,,,| 
     3       ,,||,              8        |,,|, 
     4       ,|,,|              9        |,|,, 

| represents a tall bar 
, represents a short bar 

For example, if your zip code is 15213, then the barcode that should be generated is:

,,,||,|,|,,,|,|,,,||,,||, 

EXERCISES

  1. Using Eclipse, write a simple Java program in a project named Recitation0 that contains a class named BarCodeGenerator with a main method that prints out the barcode of the zipcode of your current home address (if you live on campus, your zipcode is 15213).

    1. You should write simple static methods to print out the barcode pattern for each digit that you need (one pattern per method). For example, for the zipcode 15213, you would need four static methods, since there are four unique digits. One of the static methods might be named printOne and it would print out ,,,|| on the screen.

    2. Then use your main method to call these methods in the correct order to print out the desired bar codes.

    3. Include a comment at the top of your program that tells us what your home zip code is so we can check your answer.

  2. Once you get the program above to work correctly, modify your program so that it contains 10 static methods (besides main) to print out each barcode pattern, one method for each number. Then find out how real US postal barcodes are encoded by visiting http://support.microsoft.com/kb/214181. Modify your program so that the main method calls the other static methods in the correct order to print out the correct postal bar code for the following address (you will need to compute the required "check-sum digit" on paper):

    Homer J. Simpson 
    742 Evergreen Terrace 
    Springfield, OR 97477-1357 
    

    NOTE: There is no evidence from The Simpsons that suggests that Homer Simpson really lives in Oregon.

HANDIN

At the end of lab, create a zip file of your program and submit it to the handin server http://handin.intro.cs.cmu.edu/v1.