diff options
| author | mo khan <mo@mokhan.ca> | 2019-08-11 16:33:12 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2019-08-11 16:33:12 -0600 |
| commit | 39ae7885659d6d1c6397a900eb46898e9443b459 (patch) | |
| tree | 274f6602c7c61ccd5885f8c9a0d760804171e276 /src/Q3/README.md | |
| parent | c4eebacd3f18230c40d1c61b6570ef9fb4b646d6 (diff) | |
complete program profiles
Diffstat (limited to 'src/Q3/README.md')
| -rw-r--r-- | src/Q3/README.md | 152 |
1 files changed, 75 insertions, 77 deletions
diff --git a/src/Q3/README.md b/src/Q3/README.md index 6b7f0ac..cb113bf 100644 --- a/src/Q3/README.md +++ b/src/Q3/README.md @@ -5,107 +5,105 @@ Student ID: 3431709 1. Problem Statement: -```text -Credit card numbers follow certain patterns. -A credit card number must have between 13 and 16 digits. -It must start with 4 for Visa cards, 5 for Master cards, 37 for American Express cards, and 6 for Discover cards. -In 1954, Hans Luhn of IBM proposed the following algorithm for validating credit card numbers: -* a. Double every second digit from right to left (e.g., if number is 3 => 3 * 2 => 6) and add them together. -* b. If this doubling results in a two-digit number, then add the two digits to get a single-digit number (e.g., if number is 5 => 5 * 2 => 10 => 1+0 => 1). + Credit card numbers follow certain patterns. + A credit card number must have between 13 and 16 digits. + It must start with 4 for Visa cards, 5 for Master cards, 37 for American Express cards, and 6 for Discover cards. + In 1954, Hans Luhn of IBM proposed the following algorithm for validating credit card numbers: -So, for the credit card number 4388576018402626, doubling all second digits from the right results in + 1. Double every second digit from right to left (e.g., if number is 3 => 3 * 2 => 6) and add them together. + 1. If this doubling results in a two-digit number, then add the two digits to get a single-digit number (e.g., if number is 5 => 5 * 2 => 10 => 1+0 => 1). -```text - (2 * 2 = 4) + (2 * 2 = 4) + (4 * 2 = 8) + (1 * 2 = 2) + (6 * 2 = 12 = 1 + 2 = 3) + (5 * 2 = 10 = 1 + 0 = 1) + (8 * 2 = 16 = 1 + 6 = 7) + (4 * 2 = 8). -``` + So, for the credit card number 4388576018402626, doubling all second digits from the right results in -This totals to 4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37. + (2 * 2 = 4) + (2 * 2 = 4) + (4 * 2 = 8) + (1 * 2 = 2) + (6 * 2 = 12 = 1 + 2 = 3) + (5 * 2 = 10 = 1 + 0 = 1) + (8 * 2 = 16 = 1 + 6 = 7) + (4 * 2 = 8). -Add all digits in the odd places from right to left. -The leftmost digit of the credit card number is at index 0; + This totals to 4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37. -6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38. + Add all digits in the odd places from right to left. + The leftmost digit of the credit card number is at index 0; -Add results from steps (a) and (b) and see if divisible by 10. -If it is, then the card number is valid; otherwise invalid. + 6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38. -37 + 38 = 75 is not divisible by 10, so it is an invalid credit card number. + Add results from steps (a) and (b) and see if divisible by 10. + If it is, then the card number is valid; otherwise invalid. -Implement Luhn’s algorithm in a program to determine whether a given credit card number is valid or not. -You must test if the number of digits in the input is in the valid range (13 to 16), run Luhn’s algorithm to test its validity, -and if it is valid, print the name of the company that offers that credit card number. -``` + 37 + 38 = 75 is not divisible by 10, so it is an invalid credit card number. -2. Description of the Code: + Implement Luhn’s algorithm in a program to determine whether a given credit card number is valid or not. + You must test if the number of digits in the input is in the valid range (13 to 16), run Luhn’s algorithm to test its validity, + and if it is valid, print the name of the company that offers that credit card number. -The code implements the expected API as per the class diagram provided -in the assignment. I also included some additional private methods to -try to increase the readability of the code. The bulk of the logic for -the `Luhn` algorithm takes place in the `calculateSums` method. +1. Description of the Code: -This method reverses the credit card number then loops through each -character. As it loops through each character it checks to see if the -current index is even or odd and applys the appropriate summing rules -for that index. + The code implements the expected API as per the class diagram provided + in the assignment. I also included some additional private methods to + try to increase the readability of the code. The bulk of the logic for + the `Luhn` algorithm takes place in the `calculateSums` method. -3. Errors and Warnings: + This method reverses the credit card number then loops through each + character. As it loops through each character it checks to see if the + current index is even or odd and applys the appropriate summing rules + for that index. -Length is too short: +1. Errors and Warnings: -```bash -java -cp target/assignment2*.jar ca.mokhan.comp268.App 3 -Enter credit card #: -1334 -1334 in invalid -``` + 1. Length is too short: -Length is too long: + ```bash + java -cp target/assignment2*.jar ca.mokhan.comp268.App 3 + Enter credit card #: + 1334 + 1334 in invalid + ``` -```bash -Enter credit card #: -41111111111111111 -41111111111111111 in invalid -```` + 1. Length is too long: -Invalid card type: + ```bash + Enter credit card #: + 41111111111111111 + 41111111111111111 in invalid + ```` -```bash -Enter credit card #: -1234567890123456 -1234567890123456 in invalid -``` + 1. Invalid card type: -4. Sample Input and Output: + ```bash + Enter credit card #: + 1234567890123456 + 1234567890123456 in invalid + ``` -Valid AMEX card #: +1. Sample Input and Output -```bash -Enter credit card #: -378282246310005 -378282246310005 is offerred by American Express -``` + 1. Valid AMEX card #: -Valid Discover card #: + ```bash + Enter credit card #: + 378282246310005 + 378282246310005 is offerred by American Express + ``` -```bash -Enter credit card #: -6011111111111117 -6011111111111117 is offerred by Discover -``` + 1. Valid Discover card #: -Valid MasterCard #: + ```bash + Enter credit card #: + 6011111111111117 + 6011111111111117 is offerred by Discover + ``` -```bash -Enter credit card #: -5555555555554444 -5555555555554444 is offerred by MasterCard -``` + 1. Valid MasterCard #: -Valid Visa card #: + ```bash + Enter credit card #: + 5555555555554444 + 5555555555554444 is offerred by MasterCard + ``` -```bash -Enter credit card #: -4012888888881881 -4012888888881881 is offerred by Visa -``` -5. Discussion: + 1. Valid Visa card #: + + ```bash + Enter credit card #: + 4012888888881881 + 4012888888881881 is offerred by Visa + ``` + +1. Discussion: |
