Question

nedt card pumber Many methodstrcratrg the check iagt have ben developed nethod is shown in she iue bel the sser to enter a iv

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//EventManager.java

import java.util.Scanner;

public class EventManager {

      public static void main(String[] args) {

            //Getting the credit card number from user

            Scanner scan = new Scanner(System.in);

            System.out.print("Enter 5 digit credit card number: ");

            String number = scan.nextLine();

            //Checking for the length of number

            while(number.length()!=5){

                  System.out.print("You must enter 5 digit credit card number: ");

                  number = scan.nextLine();

            }

            char numberArray[] = number.toCharArray();

            //Checking for each the digit to be number

            for(char c: numberArray){

                  if(c<48 || c>57){

                        System.out.println("Credit card number contains illegal characters");

                        System.out.println("The Program will now exit");

                        System.out.println(number+" is NOT a valid credit card number");

                        System.exit(0);

                  }

            }

            //multiplying 2nd and 4th digits with 2

            int i1 = 2 * Character.getNumericValue(numberArray[1]);

            while(i1>=10){

                  i1 = 1+i1%10;

            }

            int i2 = 2 * Character.getNumericValue(numberArray[3]);

            while(i2>=10){

                  i2 = 1+i2%10;

            }

            int total = Character.getNumericValue(numberArray[0])+i1+Character.getNumericValue(numberArray[2])+i2;

            int check = total%10;

            if(Character.getNumericValue(numberArray[4])== (10-check)){

                  System.out.println(number+" is a valid credit card number");

            }

            else{

                  System.out.println(number+" is NOT a valid credit card number");

            }

            scan.close();

      }

}

Outputs:

ProblemsJavadoc eDeclaration Cosole 3 <terminated» EventManager [Java Applicationl C:Program Files Javaire1.8.0 16 Enter 5 di

Add a comment
Know the answer?
Add Answer to:
nedt card pumber Many methodstrcratrg the check iagt have ben developed nethod is shown in she iue bel the sser to enter a ive-digt credit cand number, with the hth dgn being the check Sigh Verity th...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT