Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Driver program which: Reads in the data from a file called: numbers.txt

ID: 3711802 • Letter: C

Question

Create a Driver program which:

Reads in the data from a file called: numbers.txt The numbers from the file should be stored into an ArrayList... A sample version of this file has been provided, but the one being tested with may have between 1 and 10000 numbers.

Generate the same number of random boolean values as the number of integers stored in the ArrayList you just filled. These boolean values should be stored in an array which is the SAME LENGTH as your ArrayList.

Use a loop to go through your data. Consider the elements which share the same index location and update the appropriate counter for each of these four situations (you should have 4 counters):

The number at the current index from the ArrayList is even and the boolean at the current index from the array is true

The number at the current index from the ArrayList is even and the boolean at the current index from the array is false

The number at the current index from the ArrayList is odd and the boolean at the current index from the array is true

The number at the current index from the ArrayList is odd and the boolean at the current index from the array is false

After processing your data, determine which of the above counters is largest and print the EXACT message from below which corresponds correctly to situation (note: in the case of ties, print all of the messages which are tied):

"There is a lot of data which is EVEN at the same index where a True is"

"There is a lot of data which is EVEN at the same index where a False is"

"There is a lot of data which is ODD at the same index where a True is"

"There is a lot of data which is ODD at the same index where a False is"

Explanation / Answer

import java.io.BufferedReader;

import java.io.FileReader;

import java.io.IOException;

import java.util.ArrayList;

public class Driver {

public static void main(String[] args) throws IOException{

ArrayList<Integer> numbers = new ArrayList<Integer>();

BufferedReader b = new BufferedReader(new FileReader("numbers.txt"));

String line = "";

while((line = b.readLine()) != null)

numbers.add(Integer.parseInt(line));

b.close();

ArrayList<Boolean> booleanValues = new ArrayList<Boolean>();

for(int i = 0; i < numbers.size(); i++)

booleanValues.add(Math.random() < 0.5);

int count1 = 0, count2 = 0, count3 = 0, count4 = 0;

for(int i = 0; i < numbers.size(); i++) {

if(numbers.get(i) % 2 == 0 && booleanValues.get(i) == true)

count1++;

else if(numbers.get(i) % 2 == 0 && booleanValues.get(i) == false)

count2++;

else if(numbers.get(i) % 2 == 1 && booleanValues.get(i) == true)

count3++;

else

count4++;

System.out.println("There is a lot of data which is EVEN at the same index where a True is " + count1);

System.out.println("There is a lot of data which is EVEN at the same index where a False is " + count2);

System.out.println("There is a lot of data which is ODD at the same index where a True is " + count3);

System.out.println("There is a lot of data which is ODD at the same index where a False is " + count4);

}

}

}

**Comment for any further queries.