2016-12-09

posted Dec 9, 2016, 6:18 AM by Samuel Konstantinovich   [ updated Dec 9, 2016, 6:18 AM ]
Compare your Barcode to the following specifications. Modify yours as needed.
We can go over any methods you wish. 

  • Constructor Detail

    • Barcode

      public Barcode(java.lang.String zip)
      constructor that initializes _zip
      Parameters:
      zip - The 5 digit zipcode
      Throws:
      java.lang.IllegalArgumentException - if zip is not the correct length or zip contains a non digit
  • Method Detail

    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
      Returns:
      A String in the format: "084518 |||:::|::|::|::|:|:|::::|||::|:|"
    • compareTo

      public int compareTo(Barcode other)
      Compares Barcodes using their numerical order (not the symbols)
      Specified by:
      compareTo in interface java.lang.Comparable<Barcode>
      Returns:
      0 when the same value, positive when this is greater than other, negative when this is less than other
    • toCode

      public static java.lang.String toCode(java.lang.String zip)
      Converts 5 digit zipcodes to barcodes.
      Parameters:
      zip - the 5 digit zip code.
      Returns:
      The barcode formatted as "|||:::|::|::|::|:|:|::::|||::|:|"
      Throws:
      java.lang.IllegalArgumentException - if zip is not the correct length or zip contains a non digit
    • toZip

      public static java.lang.String toZip(java.lang.String code)
      Converts a barcode to a 5 digit zip
      Parameters:
      code - the barcode to convert into a zipcode
      Returns:
      the 5 digit zipcode
      Throws:
      java.lang.IllegalArgumentException - when:
      • checksum is invalid
      • encoded ints are invalid
      • non-barcode characters are used
      • length of the barcode is not 32
      • the left and rigthmost charcters are not '|'
Comments