Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program in Java to identify the type of credit card associated with the

ID: 3632228 • Letter: W

Question

Write a program in Java to identify the type of credit card associated with the credit card number.The program may identify Visa, Mastercard, AMEX, and Discover card types. The programshould adhere to the following procedure

:a) First an object should request the user to provide a credit card number.

b) The above object should pass this information to another object that will verify the typeof credit card being used.

c) This object should then pass the credit card information to a third object that will displaythe information to the user.

Explanation / Answer

Hope this helps, please rate LifeSaver! import java.util.Scanner; public class CreditCardIdentifier { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter a credit card number"); String num = sc.next(); String cardtype=""; if(num.length()==15){ cardtype = "American Express"; } else if(num.substring(0,1).equals("4")&&num.length()==16){ cardtype = "VISA"; } else if(num.substring(0,2).equals("51")|| num.substring(0,2).equals("52")|| num.substring(0,2).equals("53")|| num.substring(0,2).equals("54")|| num.substring(0,2).equals("55")&& num.length()==16){ cardtype = "Mastercard"; } else if(num.substring(0,4).equals("6011")|| num.substring(0,2).equals("65")&& num.length()==16){ cardtype = "Discover"; } else cardtype = "Not a valid cardtype"; System.out.println("The card type entered is: "+cardtype); } }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote