edu.uci.ics.inf111.dvdvendor.app
Class BarCode

java.lang.Object
  extended by edu.uci.ics.inf111.dvdvendor.app.BarCode

public class BarCode
extends java.lang.Object

The BarCode class represents the bar code of the Products


Field Summary
private  java.lang.String barCodeNumber
          The String representation of the 12-digit code which this object represents.
 
Constructor Summary
BarCode(java.lang.String productCode)
          Creates a BarCode object unless the supplied digit string is illegal.
 
Method Summary
private  void checkSum(java.lang.String code)
          This function checks whether the scanned BarCode is a valid one (not in the sense whether it exists in the database, but whether the Bar code that is passed in is of correct format to calculate the Checksum.
The checksum is a Modulo 10 calculation.
1.
 boolean equals(BarCode comparedCode)
          Compare another BarCode object to this BarCode object to determine if they are effectively equal.
 java.lang.String getBarCode()
          An accessor method returning the bar code
 int hashCode()
          The hashCode is generally the final character of a BarCode, and is used to determine whether the BarCode is a legal example of its type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

barCodeNumber

private java.lang.String barCodeNumber
The String representation of the 12-digit code which this object represents.

Constructor Detail

BarCode

public BarCode(java.lang.String productCode)
        throws InvalidBarCodeException
Creates a BarCode object unless the supplied digit string is illegal.

Parameters:
productCode - A String of digits corresponding to the bar code.
Throws:
InvalidBarCodeException - Thrown if the provided String is null, too short, or fails the checksum.
Method Detail

getBarCode

public java.lang.String getBarCode()
An accessor method returning the bar code


equals

public boolean equals(BarCode comparedCode)
Compare another BarCode object to this BarCode object to determine if they are effectively equal. This occurs if the Strings they represent are identical.

Parameters:
comparedCode - The BarCode object we are comparing to.
Returns:
true if the String representations are identical, false otherwise.

hashCode

public int hashCode()
The hashCode is generally the final character of a BarCode, and is used to determine whether the BarCode is a legal example of its type.

Overrides:
hashCode in class java.lang.Object
Returns:
An int containing the hash digit.

checkSum

private void checkSum(java.lang.String code)
               throws InvalidBarCodeException
This function checks whether the scanned BarCode is a valid one (not in the sense whether it exists in the database, but whether the Bar code that is passed in is of correct format to calculate the Checksum.
The checksum is a Modulo 10 calculation.
1. Add the values of the digits in positions 1, 3, 5, 7, 9, and 11.
2. Multiply this result by 3.
3. Add the values of the digits in positions 2, 4, 6, 8, and 10.
4. Sum the results of steps 2 and 3.
5. The check character is the smallest number which, when added to the result in step 4, produces a multiple of 10.
Example: Assume the bar code data = 01234567890
1. 0 + 2 + 4 + 6 + 8 + 0 = 20
2. 20 x 3 = 60
3. 1 + 3 + 5 + 7 + 9 = 25
4. 60 + 25 = 85
5. 85 + X = 90 (next highest multiple of 10), therefore X = 5 (checksum)

Parameters:
code - The String to be checked
Throws:
InvalidBarCodeException - Thrown if the supplied code is of incorrect length or has an incorrect checksum.