Computer Science Teacher

# March, 2011

• #### The Credit Card Project

I’m a firm believer that programming projects are best when they are about things that are interesting to students. Money tends to interest them so I have long thought about a project involving credit cards. Aren’t credit cards what a lot of students think on when thinking about buying things? I’m known that were were codes in credit card numbers for a while. I was pretty sure part of the number identified the type of card and that there was some sort of checksum involved to help do a first cut validation. I just never got around to looking things up (the Bing search) until recently Doug Peterson posted a graphic about credit card validation. There is actually more to validation then what is in the graphic but not much.

One of the key pieces of this is the checksum algorithm- the LUHN Formula. Basically some digits are doubled and added to the alternate digits which are not doubled. In most cases if the least significant digit of the result is zero the number is valid. Of course valid is not the same as “has available credit” but it’s a good first cut. Doug Peterson wrote a Small Basic routine to validate the checksum. At that link you can try it out and see the source code. Or just try it as embedded below. Doug writes about how his example and my blog post came about at Writing and Sharing Code BTW. And he is right that I should write up a solution myself and it is on my todo list.

It doesn't do a full card validation though. What else is there?

• Different companies have different numbers of digits. American Express uses 13 and 16 digit numbers for example
• Diners Club and American Express cards can both start with a 3 but the next digit depends on which card you are checking.

Getting it all right requires a little bit of research. I'll leave that to the reader for now. But why else is this a good project in my opinion? Lots of chances to try different decision structures. One can also verify against a user's claims of what sort of card it is or try to calculate the type of card based on the number itself. The project lends itself to a lot of solution options. Lots of options opens the door for lots of discussion about “the best” way to do things. What do you think? Good project? If you try it with students I would love to hear how it goes. Do they find it relevant and interesting?

BTW if you are looking for projects try the projects tag to find other posts I have written about various projects.

Page 10 of 10 (28 items) «678910