Skip to content

gopinathsjsu/cmpe202-02-individual-project-devpateltech007

Repository files navigation

Individual Project - Credit Card Validator

This is my submission for the Individual Project. This application validate credit card numbers from different input files and output the result to a file.

Problem Description

The problem is to read list of credit cards from a file (CSV, JSON or XML) and verify if they are valid or not. Also need to identify what type of card it is (Visa, MasterCard, AmEx or Discover).

I implement this using Java and used 3 design patterns to make the code better and extensible.

Design Patterns Used

  1. Chain of Responsibility: I used this for the validation part. The validator pass the card number to next validator if it cannot handle it.

    • Classes: CardValidator, VisaValidator, MasterCardValidator, etc.
  2. Factory Pattern: This is used to create the Credit Card objects and also to get the correct File Parser.

    • Classes: CreditCardFactory, ParserFactory
  3. Strategy Pattern: This allow the program to handle different file formats easily. If we need to add new format, we just add new strategy.

    • Classes: CSVParser, JSONParser, XMLParser

Project Structure

  • src/main/java: Contains all the source code
  • src/test/java: Contains all the JUnit tests
  • sample_input.csv: Sample file for testing
  • input_file.json: Sample JSON input
  • sample_input.xml: Sample XML input

How to Run

You need to have Maven and Java installed.

1. Build the project

Run this command in terminal:

mvn clean compile

2. Run the application

You can run the processor with input file and output file arguments:

For CSV:

java -cp target/classes com.creditcard.CreditCardProcessor sample_input.csv output.csv

For JSON:

java -cp target/classes com.creditcard.CreditCardProcessor input_file.json output.json

For XML:

java -cp target/classes com.creditcard.CreditCardProcessor sample_input.xml output.xml

3. Run Tests

I have added JUnit tests for all the classes. You can run them using:

mvn test

Assumptions

  • Card numbers are treated as String because of leading zeros.
  • Expiration date is just passed through, logic only check the card number format.
  • For invalid cards, I create a InvalidCC object with error message.

About

cmpe202-02-individual-project-devpateltech007 created by GitHub Classroom

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages