You are on page 1of 5

/**

*Description: This is the class, where the name of the credit card is going to be done
*Class: Fall - COSC 1437.81002
*FinalProject: Credit card numbers and the case of Mobius Duck
*Date: 12/15/2015
*@author Urooj Mohammad
*@version 5.0.0
*/
public class CreditCardIssuer
{
/**
* This method will read the string to determine who is the issuer is
* @param String cardNumber value
* @return String display
* @throws Nothing is implemented
*/
public static String issuer(String cardNumber)
{
String cardName;

if(cardNumber.startsWith("44")) //This is used so that "44" can be found in the String


{
return "Visa"; //Returns the name of the card
}

else if(cardNumber.startsWith("45"))
{
return "Visa";
}

else if(cardNumber.startsWith("51"))
{
return "MasterCard";
}

else if(cardNumber.startsWith("53"))
{
return "MasterCard";
}

else if(cardNumber.startsWith("34"))
{
return "American Express (AMEX)";
}
else if(cardNumber.startsWith("37"))
{
return "American Express (AMEX)";
}

else if(cardNumber.startsWith("60"))
{
return "Discover";
}

else if(cardNumber.startsWith("31"))
{
return "JCB";
}

else if(cardNumber.startsWith("33"))
{
return "JCB";
}

else if(cardNumber.startsWith("54"))
{
return "Diners Club- North America";
}

else if(cardNumber.startsWith("55"))
{
return "Diners Club- North American";
}

else if(cardNumber.startsWith("30"))
{
return "Diners Club- Carte Blanche";
}

else if(cardNumber.startsWith("36"))
{
return "Diners Club- International";
}

else if(cardNumber.startsWith("58"))
{
return "Maestro";
}

else if(cardNumber.startsWith("67"))
{
return "Laser";
}

else if(cardNumber.startsWith("48"))
{
return "Visa Electron";
}

else if(cardNumber.startsWith("49"))
{
return "Visa Electron";
}

else if(cardNumber.startsWith("63"))
{
return "InstaPayment";
}

else
{
return "Invalid issuer";
}
}
}

/**
*Description: This is the class, in which a credit card will get validated
*Class: Fall - COSC 1437.81002
*FinalProject: Credit card numbers and the case of Mobius Duck
*Date: 12/15/2015
*@author Urooj Mohammad
*@version 5.0.0
*/
public class CreditCardValidate
{
/**
* This method will determine if the string is valid card or not
* @param String cardName value
* @return Boolean value of true or false
* @throws Nothing is implemented
*/
public boolean validate(String cardNumber)
{
int sum= 0;
boolean oddD= false;
for(int i= cardNumber.length()-1; i >= 0; i--)
{
//Reading the string
int oddDigit= Integer.parseInt(cardNumber.substring(i, i + 1));
//When the digits are in the odd position
if(oddD)
{
//Odd position digits are multiplied by 2
oddDigit *=2;
//Odd positions greater than 9
if (oddDigit > 9)
{
//Get subtracted by 9
oddDigit = (oddDigit % 10) + 1;
}
}
//add all the numbers together
sum += oddDigit;
oddD= !oddD;
}
//The check digit
return (sum % 10 == 0);
}
}

import java.util.Scanner; //This is used so that the user can input in the program
/**
*Description: This is the driver of the program, where the information of the credit card will get
outputed
*Class: Fall - COSC 1437.81002
*FinalProject: Credit card numbers and the case of Mobius Duck
*Date: 12/15/2015
*@author Urooj Mohammad
*@version 5.0.0
*/
public class CreditCardDemo
{
/**
* @param String as args
* @return Terminaion code as int, 0 for normal, anything else is error condition
* @throws Nothing is implemented
*/
public static void main(java.lang.String[] args)
{
//Credit Card number stored as a string
String cardNumber;
int response;

Scanner keyboard= new java.util.Scanner(java.lang.System.in);

java.lang.System.out.println("Hello! This program will validate your credit card number and
the issuer!");
java.lang.System.out.println("\nConclusion: true= Vaild Number!, false= Invaild Number!");

java.lang.System.out.println("\nPlease enter the number of the credit card: ");


cardNumber= keyboard.nextLine();

//Create a CreditCardValidate object card


CreditCardValidate card= new CreditCardValidate();
java.lang.System.out.println("\tCredit Card Validation: " + card.validate(cardNumber));

java.lang.System.out.println("\nIf credit card is valid, press 1 to find out issuer");


response= keyboard.nextInt();

//Used to show issuer when card is valid and to not show when card is not valid
if(response == 1)
{
//Create a CreditCardIssuer object type
CreditCardIssuer type= new CreditCardIssuer();
java.lang.System.out.println("\tCredit Card Issuer: " + type.issuer(cardNumber));
}
else
{
java.lang.System.out.println("\nInvalid Input!");
}
}
}

You might also like