Question: How would I make this program run without the use of an array class /********************************************************************************************** *Description: CatchThief is a program that reads 3 input files
How would I make this program run without the use of an array class
/**********************************************************************************************
*Description: CatchThief is a program that reads 3 input files and outputs the
*credit card numbers found commonly in all 3 text files
*input: Three files: creditCards1.txt, creditCards2.txt, creditCards3.txt
*output: Output the credit card numbers commonly found in all 3 text files.
***********************************************************************************************/
package CatchThief;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.*;
public class CatchThief {
/*
* Try...catch is used to catch the error and execute code to handle it:
*/
public static void readFile(String filePath, List
try { //credit numbers found in that file in a list
Scanner scanner = new Scanner(new File(filePath)); //use scanner object for file reading
while (scanner.hasNextLine()) {
creditList.add(scanner.nextLine());
}
scanner.close(); //close file
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
/************************************************************************************************
*Description: findCommonCredit Method reads 3 lists containing credit numbers and finds
*the common credit numbers
*Input/Output: input from three Credit card lists, output common credit card numbers
**************************************************************************************************/
public static void findCommonCredit(List
for (int i=0;i
for (int k=0;k
commonList.add(credList1.get(i)); //then it is common to all
}
}
}
}
}
/************************************************************************************************
*Description: This main method initializes the three credit cards list and one common list. And
*reads the three files and finds the common credit card number and outputs it
**Input/Output: input from three Credit card lists, output common credit card numbers
* @return
**************************************************************************************************/
public static void main(String[] args) {
/*
* the main method initializes the four strings, reads the three files and finds the common credit card number and outputs it
*/
List
List
List
List
readFile("creditCards1.txt", creditList1); //populate lists with credit card numbers
readFile("creditCards2.txt", creditList2);
readFile("creditCards3.txt", creditList3);
findCommonCredit(creditList1, creditList2, creditList3, commonList); //find common numbers
System.out.println("********************************************************");
System.out.println("Credit cards that are used by thieves in all stores:");
for (int i=0;i
System.out.println("********************************************************");
}
}
Step by Step Solution
3.52 Rating (149 Votes )
There are 3 Steps involved in it
To modify the CatchThief program to run without using the ArrayList class you can replace the ArrayList instances with simple arrays Heres the modifie... View full answer
Get step-by-step solutions from verified subject matter experts
