I have run huge piece of code. I need a UML for it. I dont what a UML is, but my professor said he needs it. Please help. Thanks.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class CreditCardValidation {
private String inputFileName;
private String outputValidCardFileName;
private String outputInvalidCardFileName;
public static void main(String[] args) {
CreditCardValidation ccValidationObj = new
CreditCardValidation();
ccValidationObj.readFile();
}
//Deafult Constrictor to inilialize instance variable
public CreditCardValidation () {
this.inputFileName = "data.txt";
this.outputValidCardFileName = "valid_cards.txt";
this.outputInvalidCardFileName = "invalid_numbers.txt";
}
//Reading input data file
public void readFile() {
Scanner sacnnerReader = null;
try {
File file = new File(inputFileName);
if (file.exists()) {
sacnnerReader = new Scanner(file);
while (sacnnerReader.hasNextLine()) {
String cradNumberString = sacnnerReader.nextLine();
String issuerName = getCardIssuer(cradNumberString);
if (isValidCardNumber(cradNumberString)) {
String outputContent = issuerName + " - " + cradNumberString;
writeFile(outputValidCardFileName, outputContent);
} else {
String outputContent = issuerName + " - " + cradNumberString;
writeFile(outputInvalidCardFileName, outputContent);
}
}
} else {
System.out.println("Input File not found");
System.exit(0);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (sacnnerReader != null) {
try {
sacnnerReader.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
//Checking weather number is invalid or valid
public boolean isValidCardNumber (String cradNumberString) {
boolean isValidFlag = true;
try {
//Calculating last digit
int lastDigit =
Integer.parseInt(String.valueOf(cradNumberString.charAt(cradNumberString.length()-1)));
//Droping last digit
String withoutLastDigit =
cradNumberString.substring(0,cradNumberString.length()-1);
//Reversing the Number
String reverseString = "";
for (int i=withoutLastDigit.length()-1;i>=0;i--) {
reverseString = reverseString + withoutLastDigit.charAt(i);
}
//Multiply the digit in ODD positions by 2 and subtract 9 to all if
any reasult higher than 9
String multiplyTwo = "";
for (int i=1;i<=reverseString.length();i++) {
//Checing ODD number
if (i%2!=0) {
//Multiplying ODD number with 2
int digit =
Integer.parseInt(String.valueOf(reverseString.charAt(i-1)))*2;
//Checking if multiplication is grater than 9 or not
if (digit>9) {
//If grater than 9, getting subtraction from 9
digit = digit-9;
//appening the subtraction with string
multiplyTwo = multiplyTwo + String.valueOf(digit);
}else {
multiplyTwo = multiplyTwo + String.valueOf(digit);
}
} else {
multiplyTwo = multiplyTwo +
String.valueOf(reverseString.charAt(i-1));
}
}
//adding all the numbers
int numbersSum = 0;
for (int i=0;i<multiplyTwo.length();i++) {
int digit =
Integer.parseInt(String.valueOf(multiplyTwo.charAt(i)));
numbersSum = numbersSum + digit;
}
//Performing MOD 10
int mod = numbersSum%10;
//Checking MOD 10 is same as card last digit or not
//If not card is invalid else valid
if (mod != lastDigit) {
isValidFlag = false;
}
}catch (Exception e) {
e.printStackTrace();
}
return isValidFlag;
}
//getting issuer name fromcard number
public String getCardIssuer (String cardNumber) {
String issuerName = "";
//Getting first two digits
int firstTwoDigit =
Integer.parseInt(cardNumber.substring(0,2));
//Switch case to find the issuer name
switch(firstTwoDigit){
case (44): issuerName = "VISA";break;
case (45): issuerName = "VISA";break;
case (51): issuerName = "MasterCard";break;
case (53): issuerName = "MasterCard";break;
case (37): issuerName = "American Express (AMEX)";break;
case (34): issuerName = "American Express (AMEX)";break;
case (60): issuerName = "Discover";break;
case (31): issuerName = "JCB";break;
case (33): issuerName = "JCB";break;
case (54): issuerName = "Diners Club - North America";break;
case (55): issuerName = "Diners Club - North America";break;
case (30): issuerName = "Diners Club - Carte Blanche";break;
case (36): issuerName = "Diners Club - International";break;
case (58): issuerName = "Maestro";break;
case (67): issuerName = "LASER";break;
case (48): issuerName = "Visa Electron";break;
case (49): issuerName = "Visa Electron";break;
case (63): issuerName = "InstaPayment";break;
}
return issuerName;
}
//Writing output file
public void writeFile(String outputFileName, String content)
{
PrintWriter printWiter = null;
try {
printWiter = new PrintWriter(new FileOutputStream(new
File(outputFileName), true));
printWiter.write(content);
printWiter.write("\n");
printWiter.flush();// Flushing File Writer
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (printWiter != null) {
printWiter.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
If you want to run it, here is part of the data in my txt file is this:
3158539628375348
3337465828248404
3112804683572030
3112804683572033
5435528978467581
6706465468107999
6304362971054667
6706169762827894
6706169762827892
4844104341377697
4913405490886727
4844885754351829
4844885754351822
6371473570875275
6381475006869978
6389057917814806
347100734345549
347100734345543
6011162533805000
6011621663574413
6011824617460743
6011824617460745
6389057917814802
4539318768050385
//(+) Sign for public
(-) Sign for private
(underline) for static
//If you need any help regarding this solution ........ please leave a comment ......... thanks
Get Answers For Free
Most questions answered within 1 hours.