//EventManager.java
import java.util.Scanner;
public class EventManager {
public static void main(String[] args) {
//Getting the credit card number from user
Scanner scan = new Scanner(System.in);
System.out.print("Enter 5 digit credit card number: ");
String number = scan.nextLine();
//Checking for the length of number
while(number.length()!=5){
System.out.print("You must enter 5 digit credit card number: ");
number = scan.nextLine();
}
char numberArray[] = number.toCharArray();
//Checking for each the digit to be number
for(char c: numberArray){
if(c<48 || c>57){
System.out.println("Credit card number contains illegal characters");
System.out.println("The Program will now exit");
System.out.println(number+" is NOT a valid credit card number");
System.exit(0);
}
}
//multiplying 2nd and 4th digits with 2
int i1 = 2 * Character.getNumericValue(numberArray[1]);
while(i1>=10){
i1 = 1+i1%10;
}
int i2 = 2 * Character.getNumericValue(numberArray[3]);
while(i2>=10){
i2 = 1+i2%10;
}
int total = Character.getNumericValue(numberArray[0])+i1+Character.getNumericValue(numberArray[2])+i2;
int check = total%10;
if(Character.getNumericValue(numberArray[4])== (10-check)){
System.out.println(number+" is a valid credit card number");
}
else{
System.out.println(number+" is NOT a valid credit card number");
}
scan.close();
}
}
Outputs:
nedt card pumber Many methodstrcratrg the check iagt have ben developed nethod is shown in she iue bel the sser to enter a ive-digt credit cand number, with the hth dgn being the check Sigh Verity th...