Complete MP4

This commit is contained in:
2022-11-16 13:22:24 -06:00
parent 6e2805fed3
commit 9935979398
3 changed files with 236 additions and 3 deletions

View File

@@ -13,7 +13,8 @@ import java.util.Scanner;
*/
public class MP4_CalebFontenot {
static boolean debug = true;
static boolean debug = false;
// Yes, I know the debugger exists. This is just a bit easier imho
/**
* 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
@@ -136,7 +137,23 @@ public class MP4_CalebFontenot {
if (userInput.equalsIgnoreCase("c")) {
System.out.print("Please enter a credit card number: ");
userInput = input.next();
break;
try { //Test to see if user has given us a string that looks like a credit card number
//Does it sucessfully convert to an integer?
Long.parseLong(userInput);
} catch(Exception e) {
System.out.println("Invalid input: String doesn't look like a credit card, it failed successfully convert into an integer.");
//break;
}
if (userInput.length() != 16) {
System.out.println("Invalid input: String doesn't look like a credit card, incorrect length.");
if (debug) {
System.out.println("length: " + userInput.length());
}
} else {
break;
}
}
}
@@ -153,7 +170,8 @@ public class MP4_CalebFontenot {
String userInput = menu();
if (userInput == "0") { // Stop program execution if credit card not entered
System.out.println("Credit card not entered!");
System.exit(0);
//System.exit(0);
return;
}
boolean creditCardValidity = MP4_CalebFontenot.isValid(userInput);