Work on MP4
This commit is contained in:
parent
4a97e1fe67
commit
00792b24e4
@ -24,12 +24,11 @@ public class MP4_CalebFontenot {
|
||||
int sumResult = MP4_CalebFontenot.sum(MP4_CalebFontenot.doubleDigitsAndSumSingleDigits(CreditCard), MP4_CalebFontenot.addOddNumbersFromRightToLeft(CreditCard));
|
||||
int divisionResult = sumResult % 10;
|
||||
if (debug) {
|
||||
System.out.println(sumResult + ", " + divisionResult);
|
||||
System.out.println(sumResult + ", " + divisionResult);
|
||||
}
|
||||
if (divisionResult == 0) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -57,19 +56,22 @@ public class MP4_CalebFontenot {
|
||||
if (debug) {
|
||||
System.out.println("Now executing addOddNumbersFromRightToLeft()");
|
||||
}
|
||||
// Iterate through string
|
||||
// Iterate through string
|
||||
int creditCardLength = creditCard.length();
|
||||
int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
|
||||
//System.out.println(creditCard.length());
|
||||
|
||||
for (int i = 0; i <= (creditCardLength -1); i = i + 2) {
|
||||
for (int i = 0; i <= (creditCardLength - 1); i++) {
|
||||
currentDigit = Character.getNumericValue(creditCard.charAt(i)); // Parses current digit as an integer so we can do math on it
|
||||
sum += currentDigit;
|
||||
if (debug) {
|
||||
System.out.println(currentDigit);
|
||||
System.out.println("sum: " + sum);
|
||||
if (currentDigit % 2 != 0) { // Is this number an odd number?
|
||||
sum += currentDigit;
|
||||
if (debug) {
|
||||
System.out.println(currentDigit);
|
||||
System.out.println("sum: " + sum);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
@ -89,8 +91,12 @@ public class MP4_CalebFontenot {
|
||||
int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
|
||||
//System.out.println(creditCard.length());
|
||||
|
||||
for (int i = (creditCardLength -1); i >= 0; i = i - 2) {
|
||||
for (int i = 0; i <= (creditCardLength - 1); i++){
|
||||
currentDigit = Character.getNumericValue(creditCard.charAt(i)); // Parses current digit as an integer so we can do math on it
|
||||
if (debug) {
|
||||
System.out.println("current digit: " + currentDigit);
|
||||
}
|
||||
if (currentDigit % 2 == 0) { //Is this number an even number?
|
||||
digitProduct = currentDigit * 2;
|
||||
if (digitProduct > 9) { // Product is larger than 9. Typecast the integer back into a string so we can seperate the digits and add them together.
|
||||
String workingString = Integer.toString(digitProduct);
|
||||
@ -103,9 +109,11 @@ public class MP4_CalebFontenot {
|
||||
digitProduct = (tensDigit + onesDigit);
|
||||
}
|
||||
sum += digitProduct;
|
||||
if (debug) {
|
||||
System.out.println(digitProduct);
|
||||
}
|
||||
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println("The sum is: " + sum);
|
||||
}
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
@ -136,9 +144,9 @@ public class MP4_CalebFontenot {
|
||||
} else {
|
||||
validityString = "invalid";
|
||||
}
|
||||
|
||||
|
||||
System.out.println("The credit card " + sampleCreditCard + " is " + validityString);
|
||||
|
||||
|
||||
/*
|
||||
String userInput = menu();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user