How To Make A Credit Card Finder On Java

in #utopian-io7 years ago (edited)

What Will I Learn?

  • You will learn how to make a credit card definer
  • You will learn how to use variables

Requirements

Write here a bullet list of the requirements for the user in order to follow this video tutorial.

  • Knowledge of coding
  • Eclipse and Java
  • Must have credit card or know how to generate one

Difficulty

  • Basic

Description

Hello,in this tutorial i made a program that defines credit cards brand by its number.With this program you can easily find out your credit or bank cards type of brand.

       import java.util.*;
public class CreditCardFinder {
public static void main(String[] args) {
 
@SuppressWarnings("resource")
Scanner input = new Scanner(System.in);
System.out.println("Write your credit card number :");
String id = input.nextLine();
 
while (id.length() != 16) {
System.out.println("Wrong Input.Credit Card Must Have 16 Numbers!");
id = input.nextLine();
}       
int x = sumAgain(id);
int y = sum(id);
 
if (isValid(x, y)) {
System.out.println("Your Card Number Is True");type(id);
} else {
System.out.println("Your Card Is Out Of Use ");
        }
    }
 
    public static int sum(String myid) {
 
int sum1 = 0;
for (int i = myid.length() - 2; i >= 0; i -= 2) {
int x = Character.getNumericValue(myid.charAt(i));
int y = x * 2;
if (y >= 10) {
int a = (y % 10) + 1;
sum1 += a;
} else
sum1 += y;
}
return sum1;
    }
 
    public static int sumAgain(String myid) {
int sum2 = 0;
for (int i = myid.length() - 1; i >= 0; i -= 2) {
    int x = Character.getNumericValue(myid.charAt(i));
sum2 += x;
}
return sum2;
    }
    
    public static boolean isValid(int x,int y) {
        if ((x + y) %10 == 0)
            return true;
        return false;
    }
    
    public static void type(String myid)
    {
    switch(Character.getNumericValue(myid.charAt(0)))
    {
    case 3:System.out.println("Your Card Is ---- American Express");break;
    case 4:System.out.println("Your Card Is ---- Visa");break;
    case 5:System.out.println("Your Card Is ---- Master Card");break;
    default:System.out.println("Your Card Is ---- Discover Card");break;
    
    }
    }
}

Video Tutorial

Sort:  

Very Good post ☺ keep posting

Thank you very much :)

Your contribution cannot be approved because it does not follow the Utopian Rules, and is considered as plagiarism. Plagiarism is not allowed on Utopian, and posts that engage in plagiarism will be flagged and hidden forever.

Almost the same code

Suggestion

  • Sure make your own contribution instead of copying .This is the first time warning.

You can contact us on Discord.

[utopian-moderator]