15-110 Introduction to Programming [Reid-Miller]


LAB 0 [Introduction to Java]

Objective

Postal Bar Codes

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 bar code that should be generated is:

...||.|.|...|.|...||..||.

Exercise

  1. Following the documentation Introduction to Eclipse, write a simple Java program in a project named Lab0 that contains a class named BarCodeGenerator. (Remember when you make the class to check the button to include a main method.) The main method should display 1) the numeric zipcode of your current home address (if you live on campus, your zipcode is 15213) and 2) its postal bar code. Use MySecondProgram on the Handouts page as model for your program.

Additional Exercises (if you have time)

  1. Once you get the program above to work correctly, write a second version of your program in your Lab0 project by adding a second class named BarCodeGenerator2, also with a main method. For this part use MyFirstProgram in the Eclipse documentation as your model.

  2. If you still have time, modify either class so that it contains either 10 static methods (besides main) or 10 variables, as appropriate, for each bar code pattern, one for each digit. Real US postal barcodes not only includes codes for the five digit zipcode but additional codes and check codes. To find out this additional coding go to the web page support.microsoft.com/kb/214181. Modify your program so that the main method prints out the following address* and its correct postal bar code:

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

    The postal bar code for this address should be:
    ||.|..|...|.|..||...||...|...||..||..|.|.|...|.|..|..|.|.|..||

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

When You're Done...

Click the following link for instructions on how to hand in your lab electronically to Blackboard:

Electronic Handin Instructions

DO NOT ERASE YOUR LAB PROJECT FOLDER, IN CASE OF A SUBMISSION ERROR.