Question: // Project1.java import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 { public static void main (String

 // Project1.java import java.io.*; // BufferedReader import java.util.*; // Scanner toread from a text file public class Project1 { public static voidmain (String args[]) throws Exception // we NEED this 'throws' clause {

// Project1.java import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 { public static void main (String args[]) throws Exception // we NEED this 'throws' clause { // ALWAYS TEST FIRST TO VERIFY USER PUT REQUIRED CMD ARGS if (args.length  java Project1 "); // i.e. C:\> java Project1.txt P1input.txt 1 30 System.exit(0); } // grab args[0] and store into a String var named infileName // grab args[1] and conver to int then store into a var named lo // grab args[2] and conver to int then store into a var named hi // STEP #1: OPEN THE INPUT FILE AND COMPUTE THE MIN AND MAX. NO OUTPUT STATMENTS ALLOWED Scanner infile = new Scanner( new File(infileName) ); int min,max; min=max=infile.nextInt(); // WE ASSUME INPUT FILE HAS AT LEAST ONE VALUE while ( infile.hasNextInt() ) { // YOUR CODE HERE FIND THE MIN AND MAX VALUES OF THE FILE // USING THE LEAST POSSIBLE NUMBER OF COMPARISONS // ASSIGN CORRECT VALUES INTO min & max INTHIS LOOP. // MY CODE BELOW WILL FORMAT THEM TO THE SCREEN // DO NOT WRITE ANY OUTPUT TO THE SCREEN } System.out.format("min: %d max: %d ",min,max); // DO NOT REMOVE OR MODIFY IN ANY WAY // STEP #2: DO NOT MODIFY THE REST OF MAIN. USE THIS CODE AS IS // WE ARE TESTING EVERY NUMBER BETWEEN LO AND HI INCLUSIVE FOR // BEING PRIME AND/OR BEING PERFECT for ( int i=lo ; i  Here is your starter file: Projectljava You must complele a partially wrillen program by axlding cole into the loop in ma, hen ilng in the two mels below min. STEP #1 FILL IN THE LOOP IN THE MAIN METHOD You are given a iut ile such as lis: Plinl.lx! which conlains around a housa nlegers The coe you writ into the loop in main must find the min and max of the file. Don't write anything to the screen, just assign the smallest value of the file into min, and the largest into max. Let my ce output of the values after the kop ends. A brute force approach to min max would be to er arm a tesl of each value lo see if it s lhe new min, then pe orm a similar tes on that same number to see if it i the new max. Such strate requires 2n comparisons on a rile o n nimhers. See if you can do it less than 2n comparisons. ALMAYS IEST FPIRSZ O VERIPY USER U REQUIRED CD ARDS if (arqs.larqth3 Systen, out .printIn(".nasage: C:\> 15va i.e > ava Projecti Plinput.txt 1 30 Syaten.xi.o Lab2   intn.); REPLACE THE 3 COMMENTS WITH CODE THAT STORES THE THREE ARG VALUES INTO VARIABLES // grab arJSIOJ and store ito  Strang var nanea in:ile grab srg1) and conve to int then store into var nane lo qab ars and conver to int then store into a var nanad hi THIS IS THE SECOND AND PLACE YOU ARE TO MODIFY MAIN

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!