Question
This is java! I need PSEUDOCODE for the following source code: //ReadFile.java import java.io.*; //import java.util.Scanner; public class ReadFile{ public static void main(String[] args) throws
This is java!
I need PSEUDOCODE for the following source code:
//ReadFile.java
import java.io.*; //import java.util.Scanner; public class ReadFile{ public static void main(String[] args) throws IOException{ Validation cc = new Validation(); try{ BufferedReader in = new BufferedReader(new FileReader("cardNumbers.txt")); String s; while((s = in.readLine()) != null){ Validation.getValidation(s); if(Validation.getValidity()==true) Validation.getCardIssuer(s); Validation.checkValidity(); //} //else //Validation.checkValidity();
System.out.println(cc.getStr()); } in.close(); }catch(FileNotFoundException e){System.out.println("File not found");}
}//end of main }//end of class
=============================================================================
//Validation.java import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter;
public class Validation { private static String str; private static boolean valid = false; public Validation(){}
public static void getValidation(String s) { setValidityFalse(); long n = Long.parseLong(s); int i, j, sum = 0; long digit, lastDigit; int length = Long.toString(n).length(); long[] list = new long[length]; long[] dropLast = new long[length - 1]; for (i = length - 1; i >= 0; i--) { digit = n % 10; list[i] = digit; n /= 10; } lastDigit = list[length - 1]; // drop last digit by copying array to dropLast array for (i = 0; i < length - 1; i++) dropLast[i] = list[i]; j = length - 1; // reverse digits for (i = 0; i <= j; i++, j--) { long temp = dropLast[j - 1]; dropLast[j - 1] = dropLast[i]; dropLast[i] = temp; } // multiple odd digits by 2 for (i = 0; i < length - 1; i += 2) { long temp = dropLast[i]; temp *= 2; if (temp > 9) temp -= 9; dropLast[i] = temp; } // add all numbers for (i = 0; i < length - 1; i++) sum += dropLast[i]; // check digit if ((sum + lastDigit) % 10 == 0){ setValidityTrue(); getCardIssuer(s); } else setValidityFalse(); }
public static void getCardIssuer(String s) { str = s;
if (str.length() == 14) { if (str.startsWith("36")) str = str.concat(" is a Diners Club-International card."); else str = str.concat(" is a Diners Club-Carte Blanche card."); } if (str.startsWith("3") && s.length() != 14) { if (str.length() == 15) str = str.concat(" is a American Express card."); else str = str.concat(" is a JCB card."); }// end of 3 if (str.startsWith("4")) { if(str.startsWith("44")||str.startsWith("45")) str = str.concat(" is a Visa card."); else if(str.startsWith("48")||str.startsWith("49")) str = str.concat(" is a Visa Electron card."); } // end of 4 if (str.startsWith("5")) { if(str.startsWith("51")||str.startsWith("53")) str = str.concat(" is a Master Card."); else if(str.startsWith("54")||str.startsWith("55")) str = str.concat(" is a Diners Club-North America card."); else if(str.startsWith("58")) str = str.concat(" is a Maestro card.");
}//end of 5 if (str.startsWith("6")) {
if(str.startsWith("60")) str = str.concat(" is a Discover card."); else if(str.startsWith("67")) str = str.concat(" is a Laser card."); else str = str.concat(" is an InstaPayment card."); } // end of 6*/ }// end of getCardIssuer
public static void setValidityTrue() { valid = true; }
public static void setValidityFalse() { valid = false; }
public static boolean getValidity() { return valid; }
public static void checkValidity() throws IOException{ PrintWriter outValid; PrintWriter outInvalid; if(valid == true){
try { outValid = new PrintWriter(new FileWriter("valid_cards.txt", true)); outValid.write(str + " "); outValid.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } else {
try { outInvalid = new PrintWriter(new FileWriter("invalid_cards.txt", true)); outInvalid.write(str+ " "); outInvalid.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } }//end of checkValidity
public String getStr() { return str; }
}// end of class
==================================================================
//cardNumbers.txt 3158539628375348 3337465828248404 3112804683572030 3112804683572033 5435528978467581 6706465468107999 6304362971054667 6706169762827894 6706169762827892 4844104341377697 4913405490886727 4844885754351829 4844885754351822 6371473570875275 6381475006869978 6389057917814806 347100734345549 347100734345543 6011162533805000 6011621663574413 6011824617460743 6011824617460745 6389057917814802 4539318768050385 36880982786892 36845793345501 36661154562232 36661154562234 5893329089846994 6761680165952016 6763100400984029 6763100400984022 5127043299122389 5330838017737340 5429168755154025 5429168755154023 375354034606481 379570632133224 4485521241443135 4532916206508075 4532916206508076 5590976687287124 5540641137519895 5540641137519892 30522070708059 30066552673241 30365487186802 30365487186801
=======================================================================
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