//Finds out if the credit card is valid or not public boolean isValid() { //Finds out if credit card number is even or odd number of digits temp = cc_num.size() % 2; //Performs Luhn's Algorithm for(i = temp; i < cc_num.size(); i += 2) { if(cc_num.elementAt(i) * 2 > 9) temp = cc_num.elementAt(i) * 2 - 9; else temp = cc_num.elementAt(i) * 2; sum += temp; } //Returns true or false based on the statement below return sum % 10 == 0; }

What's happening is that it is always returning false given the input by my instructors solution program.

A sample input would be 378282246310005

That is a valid card number but when my program performs the algorithm it doesn't work. I already having a working algorithm for Luhn's Algorithm but my instructor said it was redundant code and I should make it more concise.

Luhn's Alogithm should look like this:

"For a card with an even number of digits, double every odd numbered digit and subtract 9 if the product is greater than 9. Add up all the even digits as well as the doubled-odd digits, and the result must be a multiple of 10 or it's not a valid card. If the card has an odd number of digits, perform the same addition doubling the even numbered digits instead."

For example, "[Let's] apply the Luhn check to 4408 0012 3456 7890. (4*2)+4+(0*2)+8+(0*2)+0+(1*2)+2+(3*2)+4+(5*2-9)+6+(7*2-9)+8+(9*2-9)+0 = 8+4+0+8+0+0+2+2+6+4+1+6+5+8+9+0 = 63, which is not a multiple of 10. Therefore we conclude that the number 4408 0012 3456 7890 is an invalid credit card number."