4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

How To Make A Credit Card Finder On Java

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

https://www.youtube.com/watch?v=MBK6u_phnHQ&feature=youtu.be

Curriculum



Posted on Utopian.io - Rewarding Open Source Contributors

6 upvotes $0.00

Replies (3)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: