Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 creditList){ //function that will open a file a add all the
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 credList1, List credList2, List credList3, List commonList){
for (int i=0;ifor (int j=0;jif (credList1.get(i).equals(credList2.get(j))){ //if a credit number in 1st list matches with any credit number
for (int k=0;kif (credList1.get(i).equals(credList3.get(k))) //if that matched number is also present in 3rd list
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 creditList1 = new ArrayList(); //create lists to store credit numbers from 3 files
List creditList2 = new ArrayList();
List creditList3 = new ArrayList();
List commonList = new ArrayList(); //this list will be used to store common numbers
 
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;iSystem.out.println(commonList.get(i));
System.out.println("********************************************************");
}
}


Step by Step Solution

3.52 Rating (149 Votes )

There are 3 Steps involved in it

Step: 1

To modify the CatchThief program to run without using the ArrayList class you can replace the ArrayList instances with simple arrays Heres the modifie... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions

Question

Describe the four common parts of an insurance policy.

Answered: 1 week ago

Question

3. Use the childs name.

Answered: 1 week ago