Courses‎ > ‎AP Computer Science‎ > ‎Konstantinovich‎ > ‎notes‎ > ‎

2017-12-03 Barcode HW

posted Dec 4, 2017, 8:41 AM by Konstantinovich Samuel   [ updated Dec 5, 2017, 11:53 AM ]
  • Constructor Detail

    • Barcode

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

    • toString

      public String toString()
      Overrides:
      toString in class Object
      Returns:
      A String in the format: "|||:::|::|::|::|:|:|::::|||::|:| (92010)"
    • compareTo

      public int compareTo(Barcode other)
      Compares Barcodes using their numerical order (not the symbols)
      Specified by:
      compareTo in interface 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 String toCode(String zip)
      Converts 5 digit zipcodes to barcodes.
      Parameters:
      zip - the 5 digit zip code.
      Returns:
      The barcode formatted as "|||:::|::|::|::|:|:|::::|||::|:|"
      Throws:
      IllegalArgumentException - if zip is not the correct length or zip contains a non digit
    • toZip

      public static String toZip(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:
      IllegalArgumentException - when:
      • checksum is invalid
      • Digit sequence is not a valid number e.g :::::  or |||||
      • non-barcode characters are used
      • length of the barcode is not 32
      • the left and rigthmost charcters are not '|'

      getCode

      public String getCode()
      Accessor for the cod
      Returns:
      A String in the format: "|||:::|::|::|::|:|:|::::|||::|:|"

      getZip

      public String getZip()
      Accessor for the 5 digit zip.
      Returns:
      A String in the format: "08451"
Comments