
// This program takes in a list of credit card transactions and outputs a list of credit card numbers 
// associated with suspected fraudulent transactions.

import java.util.*;
import java.io.*;

public class FraudDetector {
    public static void main(String[] args) {
        if( args.length <= 0 || args[0].trim().length() <= 0 ){
            System.out.println("Usage: $> java FraudDetector inputfile");
            System.exit(1);
        }

        // read input file
        String inputFile = args[1];
        Scanner input = null;

        try {
            input = new Scanner(new File(inputFile));
        } catch( FileNotFoundException e ) {
            System.out.println("No such file: " + inputFile);
        }

        // declare map to collect creditcards and expense totals
        // collection will be a set of creditcard numbers mapping to a set of maps, which in turn map dates to totals
        HashMap<String, HashMap<Integer, Integer>> creditCardTotals = new HashMap<String, HashMap<Integer, Integer>>();
        
        // iterate through the transaction input file
        // e.g. 10d7ce2f43e35fa57d1bbf8b1e2, 2014-04-29T13:15:54, 10.00
        while( input.hasNextLine() ) {
            String transaction = input.nextLine();

            // split into components
            String[] transactionComponents = transaction.split(",");

            if(transactionComponents.length < 3) {
                // malformed transaction input, move to next
                continue;
            }

            HashMap<Integer, Integer> cardExists = map.get(transactionComponents[0].trim());

            if( cardExists != null ) {
                // card known in this dataset before

            } else {
                // new card to this dataset

            }
        }

        // create list of suspicious credit card numbers

        // return

    }

    // filterTransactions function takes in a list of transactions, a date and a threshold spend amount 
    // and returns a list of credit card numbers associated with transactions exceeding the threshold.
    public static void filterTransactions(String inputFile, Date date, long amountThreshold) {
        
    }
}

@@ -189,16 +189,36 @@
 va.io.*;
+%0Aimport java.text.*;
 %0A%0Apublic
@@ -521,17 +521,17 @@
  = args%5B
-1
+0
 %5D;%0A     
@@ -817,16 +817,21 @@
       //
+ this
  collect
@@ -971,23 +971,20 @@
 nteger, 
-Integer
+Long
 %3E%3E credi
@@ -1034,23 +1034,20 @@
 nteger, 
-Integer
+Long
 %3E%3E();%0A  
@@ -1461,80 +1461,427 @@
 med 
-transaction input, move to next%0A                continue;%0A            %7D%0A
+input, move to next%0A                System.out.println(%22Error parsing transaction: %22 + transaction);%0A                continue;%0A            %7D%0A%0A            String transactionCardHash = transactionComponents%5B0%5D.trim();%0A            String transactionDate = transactionComponents%5B1%5D.trim();%0A            String transactionAmount = transactionComponents%5B2%5D.trim();%0A%0A            // check if a record exists for this credit card
 %0A   
@@ -1928,19 +1928,32 @@
 xists = 
-map
+creditCardTotals
 .get(tra
@@ -1961,35 +1961,23 @@
 sactionC
-omponents%5B0%5D.trim()
+ardHash
 );%0A%0A    
@@ -2063,16 +2063,826 @@
 t before
+ - check if a total eists for this date and update it%0A                %0A                // extract day component from input e.g. %222014-04-29%22 from %222014-04-29T13:15:54%22%0A                String dayComp = transactionDate.split('T');%0A%0A                // calculate timestamp for the date%0A                try %7B%0A                    DateFormat dateFormat = new SimpleDateFormat(%22yyyy-MM-dd%22);        %0A                    Date date = dateFormat.parse(dayComp);%0A                    long time = date.getTime();%0A                    // new Timestamp(time);%0A                    // System.out.println(time);%0A                %7D catch(ParseException e) %7B%0A                    // malformed input, move to next%0A                    System.out.println(%22Error parsing date: %22 + dayComp);%0A                    continue;%0A                %7D
 %0A%0A      
@@ -2939,16 +2939,32 @@
  dataset
+ - create record
 %0A%0A      
@@ -3020,33 +3020,19 @@
 icious c
-redit card number
+ard
 s%0A%0A     

Implement initial data processing and tx. timestamps