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

need help doing this program Final Project Credit card numbers and the case of M

ID: 3770234 • Letter: N

Question

need help doing this program

Final Project Credit card numbers and the case of Mobius Duck In this project, you are assisting an investigation. The investigator asked you to help him determine the validity of credit card numbers located in a case of Mobius Duck, case number 20150510-001 Your task is to: Read the data listed below "Data to Evaluate" from a file Evaluate each number to see ifthey are representing a possible credit card number. Validate each credit card number to see if they are a valid number. Store the valid numbers and invalid numbers in a separate array Write the contents of validated credit card number array into a file called "valid cards.txt" Write the invalid credit card number array to a file called "invalid numbers.txt' Make sure to include the issuer for each group of credit card numbers identified. Your application should work with any number of credit card entries Turn in: Source code (java) files of all classes and driver class. Completed UML for application classes. Flow chart for every method that contains beyond sequential logic flow. Generated javadocs structure. Input and output files Grading: Naming standard followed for project files -2% Input and output files -2% Javadoc structure 5% Project compiled without error 91% Proper use of internal comments, docstrings, and tags 5% Self documenting field, identifier, method, static, final, and class identifiers 5% Properly validated input and output files 5% Properly used arrays to store data 5% Correct output calculated by the Luhn algorithm and card number issuer identified 71% Extra Credit: Implement the full Issuer IIN Range instead of the simplified list.

Explanation / Answer

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class CardValidate{
   static int addDigits(int d){
       if(d < 10) return d;
       else return 1 + d % 10;
   }
   public static String isValid(String c){
       String temp = c.substring(0, c.length() - 1);
       String reverse = "";
       for(int i = temp.length() - 1 ; i >= 0 ; i-- )
   reverse = reverse + temp.charAt(i);
       int sum = 0;
       for(int i = 0; i < reverse.length(); i++){
           if(i % 2 == 0) sum += addDigits(Integer.parseInt(reverse.charAt(i) + ""));
           else sum += addDigits(2 * Integer.parseInt(reverse.charAt(i) + ""));
       }
       sum = sum % 10;
       if(sum == Integer.parseInt(c.charAt(c.length() - 1) + "")){
           int x = Integer.parseInt(c.substring(0, 6));
           if(x >= 622126 && x <= 622925) return "Discover";          
          
           x = Integer.parseInt(c.substring(0, 4));
           if(x == 6011) return "Discover";
           if(x == 6304 || x == 6706 || x == 6771 || x == 6709) return "Discover";
           if(x == 5018 || x == 5020 || x == 5038 || x == 5893 || x == 6304 || x == 6759 || x == 6761 || x == 6762 || x == 6763) return "Maestro";
           if(x == 4026 || x == 4508 || x == 4844 || x == 4913 || x == 4917) return "Visa Electron";
          
          
           x = Integer.parseInt(c.substring(0, 3));
           if(x >= 300 && x <= 305) return "Diners Club-Carte Blanche";
           if(x >= 644 && x <= 649) return "Discover";
           if(x >= 637 && x <= 639) return "InstaPayment";
          
          
           x = Integer.parseInt(c.substring(0, 2));
           if(x == 34 || x == 37) return "American Express";
           if(x == 36) return "Diners Club-International";
           if(x == 54) return "Diners Club-USA & Canada";
           if(x == 65) return "Discover";
           if(x >= 51 && x <= 55) return "MasterCard";
          
           if(c.charAt(0) == '4') return "Visa";
       }
       return "Invalid";
   }
   public static void main(String args[]) throws IOException{
       Scanner in;
       in = new Scanner(new File("input.txt"));
       FileWriter writerV = new FileWriter("valid_cards.txt");
       FileWriter writerIv = new FileWriter("invalid_cards.txt");
       while(in.hasNext()){
           String cardNo = in.next();
           String valid = isValid(cardNo);
           if(valid.equalsIgnoreCase("Invalid")){
               writerIv.write(cardNo);
           }
           else{
               writerV.write(cardNo + " - " + valid);
           }
       }
       writerV.close();
       writerIv.close();
   }
}