The US Postal Service uses barcodes to sort bulk email. Bar codes use short and long vertical bars. (See the picture below.) We will represent long bars (ones) with the vertical bar character "|" and short bars (zero) with the colon ":".
Here is how a zip code is represented with these bars: Each code has a long bar "|" on both ends. In between those, there is a sequence of 6 sets of bars, where each of the first 5 sets corresponds to one of the digits in a zip code. In addition there is a check digit that makes the sum of the zip code numbers and check digit equal to a multiple of 10. Thus, zip code 95014 needs need a check digit of 1 ( 9+5+0+1+4=19 + 1 = 20).
Digits are encoded as follows:
| 7 | 4 | 2 | 1 | 0 | Code | |
| 1 | 0 | 0 | 0 | 1 | 1 | :::|| |
| 2 | 0 | 0 | 1 | 0 | 1 | ::|:| |
| 3 | 0 | 0 | 1 | 1 | 0 | ::||: |
| 4 | 0 | 1 | 0 | 0 | 1 | :|::| |
| 5 | 0 | 1 | 0 | 1 | 0 | :|:|: |
| 6 | 0 | 1 | 1 | 0 | 0 | :||:: |
| 7 | 1 | 0 | 0 | 0 | 1 | |:::| |
| 8 | 1 | 0 | 0 | 1 | 0 | |::|: |
| 9 | 1 | 0 | 1 | 0 | 0 | |:|:: |
| 0 | 1 | 1 | 0 | 0 | 0 | ||::: |
The digit is computed from the barcode by using the column number as follows:
:::|| = 0*7 + 0*4 + 0*2 + 1*1 + 1*0 = 1
|:|:: = 1*7 + 0*4 +1*2 + 0*1 + 0*0 = 9
The only exception is zero which yields the number 11 (1*7 + 1*4 + 0*2 + 0*1 + 0*0 = 11)
Write a program that can take in a numeric zip code and output a barcode, or take in a barcode and output the numeric zip code. You should display an error message dialog if the barcode is not correct. This could be because of an incorrect digit code (i.e. |||||) or a check digit that does not sum to 20. Additionally, all numeric zip codes are valid except those beginning with two consecutive zeroes (i.e. 00765 is not a valid zip, but 01765 is).
If we input 95014, you should get: ||:|:::|:|:||::::::||:|::|:::||| or vice versa. (Don't forget to strip off the | at the first and | at the end before decoding).
You should have a Digit class, a BarCode class and a Convertor class. The Convertor class should have a main method that uses dialog boxes to obtain the input and then calls the other classes for help as needed. Your output should be shown in a message dialog. Your program should work in the following way: Prompt the user to enter a zip code and then display the resulting bar code. Next, prompt for the user to enter a bar code and then you display the zip code. Next, ask the user if s/he wishes to continue. If so, go back and repeat the above set of two operations and the continuation question.
Each of the Digit and BarCode classes should include a method "public String convert()". The Digit's convert method returns a string of "|" and ":" characters. The BarCode's convert method returns a string with an integer inside.
Also, you must provide the constructors:
public Digit(String s); // e.g., "17837"
public BarCode(String s); // e.g., "||:|:: ...
that instantiate an object of each classes, respectively. You must do this because our testing (grading) mechanisms will look for it.
TURN-IN:
Digit.java
BarCode.java
Convertor.java
SPRING BREAK PREPARATION
Here in CS 1322, we're doing our part to get your ready for spring break. In this program, you'll write an applet that demonstrates the flight of a water balloon at the beach (what else would nerdy GT students be doing on spring break?) One of the earliest uses of computers (and the whole reason they were developed during WWII) was to compute artillery firing tables for the military. We are going to write a similar program only we'll be in a domain a little closer to you.
The distance (s) over the ground that a water balloon flies is given by (using a simplified formula):
new_distance = current_distance + velocity * delta_time;
And the velocity changes by:
new_velocity = current_velocity - gravity_force*delta_time;
This formula works great if we shoot the water balloon straight up. This is usually not that good an idea unless it's a really, really warm day. We actually want to set the balloon launcher at an angle that will send the balloon where we want. In this case, the velocity has to be computed as:
velocity_in_x_direction = old_velocity_in_x_direction * cosine(launch_angle)
velocity_in_y_direction = old_velocity_in_y_direction * sine(launch_angle)
In the x dimension we will assume the velocity does not change (you only need to computer the x velocity once at the start). In the y direction, it goes down by the force of gravity over time (y velocity is constantly changing).
You can then use these velocities to calculate the x,y distance.
Write an applet that uses a delta_time of 0.01, takes in a launch angle in degrees and an initial velocity in meters/sec from dialog boxes. Then plot the location of the balloon on the screen for every 1 second of flight until it hits the ground (that is the y height is once again 0). The balloon can be a small circle plotted on the screen. This is not an animation, just plot the new circle on the screen leaving the old ones still there.
Assume the gravity force (g) is constant at 9.81 m/sec^2 (I know this is not really true, which is why we needed the computers in the first place, but we will ignore the height variance for this problem).
For advanced students, you may also use the real formula:
s(t) = -0.5 * g * t^2 + v0*t. You can then plot this in a different color in the applet to visualize the difference in trajectory.
Highly motivated physics students may even want to look up the formula for the delta g vs. height and factor that into the simulation.
The following additional facts may aid you in your design:
Angle in radians = Angle in degrees * (PI / 180)
For the truly ambitious student: Perhaps include a target at the other end such as a student from a rival university. Do some fun graphics if the balloon hits its target.
TURN-IN
Cannonball.java
TrajectoryApplet.java