Question

I have run huge piece of code. I need a UML for it. I dont what...

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

Homework Answers

Answer #1

//(+) Sign for public

(-) Sign for private

(underline) for static

//If you need any help regarding this solution ........ please leave a comment ......... thanks

Know the answer?
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
Similar Questions
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { //...
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 6    at assignment2.Client.readStudents(Client.java:64)    at assignment2.Client.main(Client.java:253) void readStudents() { // Scanner class object declare Scanner readStudentFile = null; // try block begin /*System.out.println("Working Directory = " + System.getProperty("user.dir")); // for debugging purposes only*/ try { // open file readStudentFile = new Scanner(new File("student.txt")); // loop until end of file while (readStudentFile.hasNextLine()) { String stu = readStudentFile.nextLine(); String[] eachStu; eachStu = stu.split(" "); String firstName = null, middleName = null, lastName = null; long id...
i am trying to wrire a word and change it to capital letters using client-server. im...
i am trying to wrire a word and change it to capital letters using client-server. im not able to write any words when i run the file in netbeans or command promot. is it something with my code? /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package assignment3retake; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter;...
I cannot for the life of me get this program to run properly. I don't know...
I cannot for the life of me get this program to run properly. I don't know what I'm doing wrong. Could the format of my text files be the issue? Edit: The program works this way, you choose a year and a gender and then enter a name. When you press the button its should give you the ranking or popularity of the name. There are 5 files that I have to search through, named 2006.txt to 2010.txt. First the...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The...
THIS IS FOR JAVA I have to write a method for a game of Hangman. The word the user is trying to guess is made up of hashtags like so " ###### " If the user guesses a letter correctly then that letter is revealed on the hashtags like so "##e##e##" If the user guesses incorrectly then it increments an int variable named count " ++count; " String guessWord(String guess,String word, String pound) In this method, you compare the character(letter)...
I am a beginner when it comes to java codeing. Is there anyway this code can...
I am a beginner when it comes to java codeing. Is there anyway this code can be simplified for someone who isn't as advanced in coding? public class Stock { //fields private String name; private String symbol; private double price; //3 args constructor public Stock(String name, String symbol, double price) { this.name = name; this.symbol = symbol; setPrice(price); } //all getters and setters /** * * @return stock name */ public String getName() { return name; } /** * set...
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String...
in java need uml diagram import java.util.ArrayList; import java.util.*; public class TodoList { String date=""; String work=""; boolean completed=false; boolean important=false; public TodoList(String a,String b,boolean c,boolean d){ this.date=a; this.work=b; this.completed=c; this.important=d; } public boolean isCompleted(){ return this.completed; } public boolean isImportant(){ return this.important; } public String getDate(){ return this.date; } public String getTask(){ return this.work; } } class Main{ public static void main(String[] args) { ArrayList<TodoList> t1=new ArrayList<TodoList>(); TodoList t2=null; Scanner s=new Scanner(System.in); int a; String b="",c=""; boolean d,e; char...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list...
Assignment 1 - ITSC 2214 I have to complete the array list for a shopping list code and can't figure out how to complete it: Below is the code Complete the three empty methods (remove(), find(), and contains()) in the ShoppingListArrayList.java file. These methods are already implemented in the ShoppingListArray class. /////////////////////////////////////////////////////////////////////////////////////////////////////////// Grocery Class (If this helps) package Shopping; public class Grocery implements Comparable<Grocery> { private String name; private String category; private int aisle; private float price; private int quantity;...
Here is my java code, I keep getting this error and I do not know how...
Here is my java code, I keep getting this error and I do not know how to fix it: PigLatin.java:3: error: class Main is public, should be declared in a file named Main.java public class Main { ^ import java.io.*; public class Main { private static BufferedReader buf = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String english = getString(); String translated = translate(english); System.out.println(translated); } private static String translate(String s) { String latin =...
<<<<<<<< I need only the UML diagram for ALL classes.Java???????????? public class House {    private...
<<<<<<<< I need only the UML diagram for ALL classes.Java???????????? public class House {    private int houseNumber;    private int bedrooms;    private int sqFeet;    private int year;    private int cost;    public House(int houseNumber,int bedrooms,int sqFeet, int year, int cost)    {        this.houseNumber = houseNumber;        this.bedrooms = bedrooms;        this.sqFeet = sqFeet;        this.year = year;        this.cost = cost;    }    public int getHouseNumber()    {        return houseNumber;    }   ...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT