Published: 22 Feb 2018 › Updated: 22 Feb 2018
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
Curriculum
Posted on Utopian.io - Rewarding Open Source Contributors
Leave How To Make A Credit Card Finder On Java to:
Read more #utopian-io posts
Best Posts From milliar
We have not curated any of milliar's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From milliar
- How To Build U.S.A Voting System Applet On Java Eclipse
- How To Make Music Loops And Reverse And More On Mixxx
- How To Change Language On Mixxx
- How To Make A Credit Card Finder On Java
- About Gmat
- Introducing Gmat And Making Changes On Lunar Project
- Infinity
- Discovering The Constellations On Stellarium : Capricornus
- Terminating Arrays With Program That Finds Out Transpose Of Entered Matrix [ Jeclipse Course 4 ]
- Adding "Search Button" In Following Section