announcements‎ > ‎


posted Dec 21, 2015, 8:52 AM by Samuel Konstantinovich   [ updated Dec 21, 2015, 9:06 AM ]
1. Run your LabGUI so I can see it.
2. Work on your other stuff:

Create an data type to represent Postal Bar Codes:

A bar code is generated from a 5 digit zip code by representing each digit with
a combination of 3 half bars and 2 full bars. Note that leading 0's are allowed
for zip codes. 

Represent a full bar with "|" and a half bar with ":".

To represent each of the 10 digits uniquely, the codes use the following scheme:

1  :::||   
2  ::|:|
3  ::||:
4  :|::|
5  :|:|:
6  :||::
7  |:::|
8  |::|:
9  |:|::
0  ||:::   

A check digit is added to the right of a zip code. The check digit is equal
to the sum of the digits of the zip code modulo 10.

For example,
   if the zip code is : 08451
   then the check digit is : 8
   thus the zip + check digit is : 084518

A bar code has a 2 guard rails (full bars) that lead and end the code.

So the bar code of 084518 is:


Implement the following constructors and methods.

public class BarCode implements Comparable{
// instance variables
   private String _zip;
   private int _checkDigit;

// constructors
//precondtion: zip.length() = 5 and zip contains only digits.
//postcondition: throws a runtime exception zip is not the correct length
//               or zip contains a non digit
//               _zip and _checkDigit are initialized.
public BarCode(String zip) {}

// postcondition: Creates a copy of a bar code.
public BarCode(BarCode x){}

//post: computes and returns the check sum for _zip
private int checkSum(){}

//postcondition: format zip + check digit + barcode 
//ex. "084518  |||:::|::|::|::|:|:|::::|||::|:|"      
public String toString(){}

public boolean equals(Object other){}
// postcondition: false if the object is not a BarCode, 
// false if it is a non-matching barcode
// true when they match.

public int compareTo(Comparable other){}
// postcondition: compares the zip + checkdigit