Work on MP4

This commit is contained in:
Chloe Fontenot 🏳️‍⚧️ 2022-11-14 21:14:43 -06:00
parent 4a97e1fe67
commit 00792b24e4

View File

@ -28,8 +28,7 @@ public class MP4_CalebFontenot {
} }
if (divisionResult == 0) { if (divisionResult == 0) {
return true; return true;
} } else {
else {
return false; return false;
} }
} }
@ -62,14 +61,17 @@ 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 = 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
if (currentDigit % 2 != 0) { // Is this number an odd number?
sum += currentDigit; sum += currentDigit;
if (debug) { if (debug) {
System.out.println(currentDigit); System.out.println(currentDigit);
System.out.println("sum: " + sum); 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,8 +109,10 @@ public class MP4_CalebFontenot {
digitProduct = (tensDigit + onesDigit); digitProduct = (tensDigit + onesDigit);
} }
sum += digitProduct; sum += digitProduct;
}
if (debug) { if (debug) {
System.out.println(digitProduct); System.out.println("The sum is: " + sum);
} }
} }
return sum; return sum;