CS 1301 Program 3 Fall 2014


Design, Test Cases, Source Code due: Friday, Oct 24th by 11:59PM

Grading Criteria for Program 3 CS 1301 Fall 2014

Syntax checking- if it does not run without errors or warnings, it will not be graded
Program
Correctness
60

Gets data from user

Functions are defined properly and of the correct type

sumOfDoubleEvenPlace function correct

getDigit function correct

sumOfOddPlace function correct

getDigit function correct

prefixMatched function correct

getSize function correct

getPrefix function correct

Loops used correctly

Displays results correctly, both values, text and formatting (line breaks, etc.)
Testing 15

Test cases /15
Program Design 15

Individual design /15

Design and source code are NOT the same thing (10 point penalty!)
Style and
documentation
10

Prolog Comment with Name, Section, Email, Date, Purpose

Meaningful Variable Names

Documentation of Code

Source code Indentation/
   formatting/ whitespace
Total 100
Late Penalty

I have the authority to deduct points for other items which do not follow the program specifications, as given in the assignment page, or the documentation or other standards stated on the class web page.

Educational Goals: The educational goals of this program are that the student should use the concepts of

Problem Description:

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
6 for Discover cards

In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine if a card number is entered correctly or if a credit card is scanned correctly by a scanner. Almost all credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustration, consider the card number 4388576018402626):

  1. Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number.
    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
  2. Now add all single-digit numbers from Step 1.
    4 + 4 + 8 + 2 + 3 + 1 + 7 + 8 = 37
  3. Add all digits in the odd places from right to left in the card number.
    6 + 6 + 0 + 8 + 0 + 7 + 8 + 3 = 38
  4. Sum the results from Step 2 and Step 3.
    37 + 38 = 75
  5. If the result from Step 4 is divisible by 10, the card number is valid; otherwise, it is invalid. For example, the number 4388576018402626 is invalid, but the number 4388576018410707 is valid.
Write a program that prompts the user to enter a credit card number as a long integer. Display whether the number is valid or invalid.

Sample interaction with the program:

Example run 1:
Enter a credit card number as a long integer: 4246345689049834
4246345689049834 is invalid



Example run 2:
Enter a credit card number as a long integer: 4388576018410707
4388576018410707 is valid



Notes:

Your main functions MUST look like this---make no changes to it:
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    
    System.out.print("Enter a credit card number as a long integer: ");
    long number = input.nextLong();
    
    if (isValid(number))
      System.out.println(number + " is valid");
    else
      System.out.println(number + " is invalid"); 
  }

Test Cases

First, read the assignment carefully. Look for how the program is supposed to behave. You do not know what the code looks like - that is fine. The assignment gives some examples of normal runs. There are other test cases needed. Create a test case table similar to that of program 1. The test cases are due at the same time your design and code are due.

Design


Decide on what steps you will need to perform to solve this problem. Make a numbered list and put it in Java form. Save this Java file as "design3.java". Each function should have steps numbered from 1
// main function
// step 1: prompt for credit card number 
// ... enter your steps here
// compute things
// output things


// isValid function
// step 1: 
// step 2:
// fill in the rest of the design

//  design the other functions
...

and individually fill in the missing steps in the design. This is due by Friday, October 24th, 11:59PM same time the code and test cases.

Implement the design

Write a Java program to implement your design. Make a copy of the Java file you have that has the design in it and write your Java code between the commented lines of the design. Make sure you eliminate any syntax and semantics errors. Here is where test cases come in handy! Submit your individual source code with the link here. Choose the menu choices of "Code" and "Program 1". This is due by Friday, October 24th, 11:59PM.

There are several specifications about how your program should be written.

Please read the documentation standard on the class web page. As you can see from looking at the grading criteria, we will be looking to see how you meet these standards. Note particularly that we require a prolog!

Remember that the program must run with NO errors or warnings. If it does not, it will not be graded!