Question
I need a pseudocode, flowchart and UML Diagram: import java.util.Scanner; //import Scanner Class public class CreditCard { public static void main(String[] args) { Scanner input=new
I need a pseudocode, flowchart and UML Diagram:
import java.util.Scanner; //import Scanner Class public class CreditCard { public static void main(String[] args) { Scanner input=new Scanner(System.in); long cardNumber1; System.out.println("Enter a credit card number as a long integer"); cardNumber1=input.nextLong(); if(isValid(cardNumber1)) System.out.println (cardNumber1+" is valid "); else System.out.println (cardNumber1+" is invalid "); long cardNumber2; System.out.println ("Enter a credit card card number as a long integer"); cardNumber2=input.nextLong(); if(isValid(cardNumber2)) System.out.println (cardNumber2+" is valid "); else System.out.println (cardNumber2+" is invalid "); }
public static boolean isValid(long number) { boolean valid=false; int digitsCount=getSize(number); int prefix=(int) getPrefix(number,1); if((digitsCount>=13 &&digitsCount<=16 ) && prefixMatched(number, prefix)) { long sum= sumOfDoubleEvenPlace(number)+ sumOfOddPlace(number); if (sum%10==0) valid=true; } return valid; } public static int sumOfDoubleEvenPlace(long number) { int evenSum=0; long rem; int n; while(number>0) { rem=(number/10)%10; n=(int) rem; int result=getDigit(n*2); evenSum+=result; number=(number/10)/10; } return evenSum; } public static int getDigit(int number) { int total=0; if(number>=1 && number <=9) return number; else { while(number>0) { int r=number%10; total+=r; number=number/10; } } return total; } public static int sumOfOddPlace(long number) { int oddSum=0; long rem; int n; while(number>0) { rem=number%10; n=(int) rem; oddSum+=n; number=(number/10)/10; } return oddSum; } public static boolean prefixMatched(long number,int d) { boolean matched=false; switch(d) { case 4:matched=true;break; case 5:matched=true;break; case 6:matched=true;break; case 37:matched=true;break; } return matched; } public static int getSize(long d) { int size=0; while(d>0) { d=d/10; size++; } return size; } public static long getPrefix(long number,int k) { if(getSize(number) return number; long result=0; while(number>0) { number=number/10; if(getSize(number)<=k) { result=number; break; } } return number; } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started