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

JAVA LANGUAGE PLEASE Problem #2: Fun With Files (40 points) Create a Driver prog

ID: 3710185 • Letter: J

Question

JAVA LANGUAGE PLEASE

Problem #2: Fun With Files (40 points)

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 1000 random numbers between 50 and 20000 (50 and 20000 should be included in the range). These numbers should be stored in an array.

Determine the maximum value from the numbers in the ArrayList (must have loop that goes through the ArrayList to examine the values in the ArrayList to receive full credit)

Determine the maximum value from the numbers in the array (must have loop that goes through the array to examine the values in the array to receive full credit)

Print the two max values determined by the code along with the EXACT correct message from below:

If ArrayList has the higher maximum value, print "The largest number is in the file!"

If array has the higher maximum value, print "The largest number was randomly generated!"

If the maximum values are equal, print "The file and the randomly generated data both have the same maximum value!"

Grading Breakdown:

8 -- Reading data into the ArrayList correctly and completely

8 -- Correctly and completely generating numbers in the correct range and storing those numbers in an array

8 -- Correctly and completely using a loop to determine the maximum number in the ArrayList

8 -- Correctly and completely using a loop to determine the maximum number number in the array

8 -- Correctly and completely providing the required output of the program

Here are the numbers:

404
411
329
28
381
114
50
103
342
433
318
189
79
376
346
295
19
469
96
421
197
351
225
62
244
48
310
391
427
313
326
488
434
416
435
407
283
417
319
330
482
338
374
61
480
220
291
452
470
98
71
19
378
57
461
232
374
35
41
311
363
441
456
425
394
16
274
42
41
339
327
160
76
79
394
342
118
489
288
331
377
112
10
208
330
100
383
344
102
407
4
269
10
271
329
49
284
269
137
245

Explanation / Answer

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class Sort {

   public static void main(String args[])
   {
       String str="numbers.txt";
       ArrayList<Integer> arr=new ArrayList<Integer>();
       BufferedReader br;
       try{
           br=new BufferedReader(new FileReader(str)); //Storing the file in buffer
           String read;
           System.out.println("List from the file is ");
           while((read=br.readLine())!=null) //Reading from the file
           {
               int d=Integer.parseInt(read);
               arr.add(d); //Storing the number in ArrayList
               System.out.println(d);
           }
       }catch (IOException e) {
           // TODO Auto-generated catch block
           e.printStackTrace();
       }
       int array[]=new int[1000];
       int max=20000,min=50;
       System.out.println("Randomly generated array ");
       for(int i=0;i<1000;i++)
       {
           Random rand = new Random();
                array[i]= rand.nextInt((max - min) + 1) + min; //Randomly generating the numbers
                System.out.println(array[i]);
       }
       int max_file=0; //Storing maximum from file
       int max_array=0;//Storing maximum from array
       for(int i=0;i<arr.size();i++)
       {
           if(arr.get(i)>=max_file)
           {
               max_file=arr.get(i);
           }
       }
       for(int i=0;i<1000;i++)
       {
           if(array[i]>=max_array)
           {
               max_array=array[i];
           }
       }
       System.out.println("Maximum value of file is "+max_file);
       System.out.println("Maximum value of array is "+max_array);
          if(max_file>max_array)
          {
              System.out.println("The largest number is in the file!");
          }
          if(max_array>max_file)
          {
              System.out.println("The largest number was randomly generated!");
          }
          else if(max_array==max_file)
          {
              System.out.println("The file and the randomly generated data both have the same maximum value!");
          }
   }

}