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

2017-12-01

posted Dec 1, 2017, 10:14 AM by Konstantinovich Samuel   [ updated Dec 1, 2017, 11:53 AM ]
Total Time Waster:
adventofcode.com

Git Cheat Sheet! 

Goal: Create an data type to represent Postal Bar Codes:

Read the description, discuss as needed.

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:
"|" + 0 + 8 + 4 + 5 + 1 + 8 + "|"
|   ||:::   |::|:  :|::|  :|:|: :::||  |::|:   |
"|||:::|::|::|::|:|:|::::|||::|:|"
      
Spend 3 minutes:

-What public methods of a barcode class would be useful? List them!
-What should the toString look like?


On git: MKS21X/07Barcode






Comments