Theory |
Do the following questions from Schneider & Gersting Third Edition: |
Programming |
Credit card companies use built-in "checksums" as added security measures when creating the account numbers on credit cards. This means that there are only certain valid credit card numbers, and validity can instantly be detected by using an algorithm that may involve adding up parts of the numbers or performing other checks. In this assignment, you will implement a security algorithm on a credit card number, and your program will indicate whether or not the card number is valid, according to the security check. Note that this algorithm is purely made-up; don't try to use it to create fake credit card numbers! :-)
First, implement a class called CreditCard. This class will have attributes "name", "cardNumber",
and "expirationDate";
all three are Strings. Include accessors and constructors as necessary. The credit card number must
be represented the format Then, implement a class called CreditCardVerifier. It should contain a static method called "verifyCreditCard" that takes a CreditCard as a parameter and then returns true if the credit card number and expiration date conform to the following rules:
Hint: valid card numbers according to this set of rules include 4807-6052-1766 and 4094-3460-2754, both with expiration dates of 11/10. You should use these for testing out your program. To do this, you will need to use various methods of the String class, described in Big Java section 4.6 and in the Java online documentation for String. Last, create a class called CreditCardTest that prompts the user to enter a credit card number and expiration date, creates a CreditCard object, and then uses the verifyCreditCard method to report whether or not the card number is valid. It should NOT explain why in plain English. However, for testing purposes you can report an "error code" that corresponds to the numbers of the validity checks above (this will affect how you implement the return value of the "verifyCreditCard" method).
In your program, you can assume that the credit card number and expiration date are correctly entered by the
user in the form
Want more extra credit? For 10 points extra credit, create a class called CreditCardHacker that has a "main" method that randomly generates 10,000,000 credit card numbers and reports which ones pass the test in the CreditCardTest's verifyCreditCard method. To "cheat" a little, you can set the first digit to 4 and use 11/10 as the expiration date (otherwise it's somewhat unlikely you will find any valid card numbers). Please be sure to include a "README" file with your submission. For this assignment, it should be about two or three paragraphs long. You should explain how your program works, how to run it, what the output means, and how you performed all of the checks.
|
Grading |
The Theory assignment will be worth a total of 40 points. Questions 1 and 16 are worth five points each; the others are worth 10. The Programming assignment will be worth a total of 60 points, distributed as follows:
|
Submitting your assignment |
For the Theory assignment, print a paper copy and submit it at the beginning of class. You do not need to submit it electronically. For the Programming assignment, submit a paper copy of all your source code and submit it electronically by the due date. Put all your .java files and your README file in a .zip or .tar file, then follow these instructions:
|