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 sumResult = MP4_CalebFontenot.sum(MP4_CalebFontenot.doubleDigitsAndSumSingleDigits(CreditCard), MP4_CalebFontenot.addOddNumbersFromRightToLeft(CreditCard));
|
||||||
int divisionResult = sumResult % 10;
|
int divisionResult = sumResult % 10;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
System.out.println(sumResult + ", " + divisionResult);
|
System.out.println(sumResult + ", " + divisionResult);
|
||||||
}
|
}
|
||||||
if (divisionResult == 0) {
|
if (divisionResult == 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -57,19 +56,22 @@ public class MP4_CalebFontenot {
|
|||||||
if (debug) {
|
if (debug) {
|
||||||
System.out.println("Now executing addOddNumbersFromRightToLeft()");
|
System.out.println("Now executing addOddNumbersFromRightToLeft()");
|
||||||
}
|
}
|
||||||
// Iterate through string
|
// Iterate through string
|
||||||
int creditCardLength = creditCard.length();
|
int creditCardLength = creditCard.length();
|
||||||
int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
|
int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
|
||||||
//System.out.println(creditCard.length());
|
//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
|
currentDigit = Character.getNumericValue(creditCard.charAt(i)); // Parses current digit as an integer so we can do math on it
|
||||||
sum += currentDigit;
|
if (currentDigit % 2 != 0) { // Is this number an odd number?
|
||||||
if (debug) {
|
sum += currentDigit;
|
||||||
System.out.println(currentDigit);
|
if (debug) {
|
||||||
System.out.println("sum: " + sum);
|
System.out.println(currentDigit);
|
||||||
|
System.out.println("sum: " + sum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +91,12 @@ public class MP4_CalebFontenot {
|
|||||||
int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
|
int currentDigit, digitProduct, tensDigit, onesDigit, sum = 0;
|
||||||
//System.out.println(creditCard.length());
|
//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
|
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;
|
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.
|
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);
|
String workingString = Integer.toString(digitProduct);
|
||||||
@ -103,9 +109,11 @@ public class MP4_CalebFontenot {
|
|||||||
digitProduct = (tensDigit + onesDigit);
|
digitProduct = (tensDigit + onesDigit);
|
||||||
}
|
}
|
||||||
sum += digitProduct;
|
sum += digitProduct;
|
||||||
if (debug) {
|
|
||||||
System.out.println(digitProduct);
|
}
|
||||||
}
|
if (debug) {
|
||||||
|
System.out.println("The sum is: " + sum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return sum;
|
return sum;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user