I really really need help witht this I am really bad with da

I really really need help witht this I am really bad with data validation can some do this for me and explain how it works and no string methods please!!!

Credit card number must be read as a long integer.
Also a credit card number must be checked to see if the numbers are entered
correctly. To do this we use the Luhn check or Mod 10 check algorithm. In this
program we will use the mod 10 algorithm. In order to validate a credit card
number using the Mod 10 algorithm you must follow the following steps: as an
example consider the card number: 4867483921456783
1. Double every even placed digit from right to left. If the result of the
doubling the number is a two-digit number add the two digits to get a one
digit number:
a. 8 + 8 = 16 , since 16 is a two-digit number therefore: 1 + 6= 7
b. 6 + 6 = 12, since 12 is a two-digit number therefore : 1 + 2= 3
c. 4 + 4 = 8
d. 2 + 2= 4
e. 3 + 3= 6
f. 4 + 4= 8
g. 6 + 6 = 12, 1 + 2 = 3
h. 4 + 4 = 8
2. Add all the single digits from the step 1
a. 7 + 3 + 8 + 4 + 6 + 8 + 3 + 8 = 47
3. Add all the odd placed digits in the credit card number
a. 3 + 7 + 5 + 1 + 9 + 8 + 7 + 8 = 48
4. Add the steps 2 and 3 result together
a. 47+ 48 = 95
5. If the result from the step 4 is divisible by 10 the credit card number is valid
a. 95 is not divisible by 10 therefore the 486748392145678 3 is not
valid
Design a program that prompt the user to get the credit card number as a long
integer and displays weather the number is valid or not.
A shell for your program has been also provided.
You must check your program with different data. Some credit card numbers have
been provided for you. Here are some valid credit card numbers that you can use
to test your program

Sample output
***********************************************
This program will determine if you
have entered a valid credit card number
Credit cards that we check includes Visa, Master Card, Discover cars and American express
************************************************
Enter a credit card number: 4024007109344696
This is a valid \"Visa\" credit card number


Would you like to validate another credit card? y/n y


Enter a credit card number: 53999907134818
The number entered is not 13 or 16 numbers long.
This is not a valid credit card number


Would you like to validate another credit card? y/n y


Enter a credit card number: 5399990713934818
This is a valid \"Master Card\" credit card number


Would you like to validate another credit card? y/n y


Enter a credit card number: 6011397131991568
This is a valid \"Discover\" credit card number


Would you like to validate another credit card? y/n y


Enter a credit card number: 372357384805028
This is a valid \"American Express\" credit card number


Would you like to validate another credit card? y/n y


Enter a credit card number: 572357384805028
This is not a valid credit card number


Would you like to validate another credit card? y/n n


Have a nice day!

shell:

Solution

import java.util.*;

public class HelloWorld
{
   /*prompt the user to get the credit card number
    call the method isvalid, this is the only method call that you can have in the main method
    output the result*/

   public static void main(String[] args)
   {
       boolean flag=true;
         Scanner read=new Scanner(System.in);
         long number;
         char choice;
        do
        {
            System.out.println(\"***********************************************\");
            System.out.println(\"This program will determine if you have entered a valid credit card number \");
            System.out.println(\"Credit cards that we check includes Visa, Master Card, Discover cars and American express\");
            System.out.println(\"***********************************************\");
            System.out.print(\"Enter a credit card number: \");
            number=read.nextLong();
            if(isValid(number))
            System.out.println(\"This is a valid \"+creditType(number)+\" credit card number\");
            else
            {
                System.out.println(\"The number entered is not 13 or 16 numbers long.\");
                System.out.println(\"This is not a valid credit card number\");
            }
            System.out.println(\"Would you like to validate another credit card? \");
            choice=read.next().charAt(0);
            if(choice==\'y\')
            flag=true;
            else
            flag=false;
        }while(flag);
    
   }
   /*call the other methods to determine if the credit card number is valid or not
    methods that you need to call in here are lengthValidation, prefixDigitValidation,
    sumOfOddPlaced, sumOfDoubleEvenPlaced, isDivisibleByTen*/
   public static boolean isValid(long number)
   {
       int total=sumOfDoubleEvenPlaced(number) + sumOfOddPlaced(number);
       if(isDivisableByTen(total) && LengthValidation(number) && prefixDigitValidation(number))
       return true;
       else
       return false;
   }
    /*check the number of the digits in the credit card to see if it is valid or not */
   public static boolean LengthValidation(long number)
   {
      int count = 0;
        while (number > 0) {
            number = number / 10;
            count++;
        }
        if(count==13 || count==16)
       return true;
       else
       return false;
  
   }
    /*this method return true if num is divisible by ten*/
   public static boolean isDivisableByTen(int num)
   {
        if(num%10==0)
       return true;
       else
       return false;
   }
  
    /*check the prefix digits to see if they are valid a type , refer to the provided table*/
   public static boolean prefixDigitValidation(long number )
   {
      StringBuilder sb = new StringBuilder();
      sb.append(\"\");
      sb.append(number);
      String cardNumber = sb.toString();
      String cType;
      if (cardNumber.startsWith(\"4\") || cardNumber.startsWith(\"5\") || cardNumber.startsWith(\"6\") ||cardNumber.startsWith(\"37\"))
        return true;
        else
        return false;
   }
   /*returns the tpye of the credit card by checking the prefix*/
   public static String creditType(long num)
   {
    
      StringBuilder sb = new StringBuilder();
      sb.append(\"\");
      sb.append(num);
      String cardNumber = sb.toString();
      String cType=\"\";
      if (cardNumber.startsWith(\"4\"))
        {
            cType = \"Visa\";
        }
        else if (cardNumber.startsWith(\"5\"))
        {
            cType = \"MasterCard\";
        }
        else if (cardNumber.startsWith(\"6\"))
        {
            cType = \"Discover\";
        }
        else if (cardNumber.startsWith(\"37\"))
        {
            cType = \"American Express\";
        }
        return cType;
   }
   
    /*calculates the sum of odd placed digits*/
   public static int sumOfOddPlaced(long number)
   {
        int result = 0;
        while (number > 0) {
            result += (int) (number % 10);
            number = number / 100;
        }

        return result;
    
   }
    /*calculate the sum of the double even palced digit. refer to the Mod 10 algorithm
    need to call the method isDoubleDigit in here*/

   public static int sumOfDoubleEvenPlaced(long number)
   {
       int result = 0;
        long temp = 0;

        while (number > 0) {
            temp = number % 100;
            result += isDoubleDigit((int) (temp / 10) * 2);
            number = number / 100;
        }

        return result;
   }
    /*if the parameter to this method is a two-digit number then this method needs to return the sum of the digits,
    or example if this method gets the value 34, then it return 3 + 4 which is 7
    if it gets the value 7 then it should return 7 since it is a single digit*/

   public static int isDoubleDigit(int number)
   {
          if (number <= 9) {
            return number;
        } else {
            int firstDigit = number % 10;
            int secondDigit = (int) (number / 10);

            return firstDigit + secondDigit;
        }
   }
   /*describe what the program does. include your name as well*/
   public static void description()
   {
     
   }
  
}  

I really really need help witht this I am really bad with data validation can some do this for me and explain how it works and no string methods please!!! Credi
I really really need help witht this I am really bad with data validation can some do this for me and explain how it works and no string methods please!!! Credi
I really really need help witht this I am really bad with data validation can some do this for me and explain how it works and no string methods please!!! Credi
I really really need help witht this I am really bad with data validation can some do this for me and explain how it works and no string methods please!!! Credi
I really really need help witht this I am really bad with data validation can some do this for me and explain how it works and no string methods please!!! Credi

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site