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

inputData.txt file -15 -57 -75 -93 -42 -1 -9 -63 -77 -12 please follow the direc

ID: 3801870 • Letter: I

Question

inputData.txt file

-15
-57
-75
-93
-42
-1
-9
-63
-77
-12

please follow the directions carefully and do as stated, thanks!

Problem Statement: The following method does not appear to be working properly if all data are negative numbers. You are asked to write a test driver class that will test this method in order to identify the issue with the code. The driver class will first read a data (from an input file called "inputData.txt") into an integer array then call the method with different input parameters to test its functionality. Finds the target value in array elements x[start] through x[last]. 2param x array whose largest value is found 2param start first subscript in range Oparam last last subscript in range Creturn the largest value of x[start] through x[last] Opre first last public int findMax(int x, int start, int last) if (start last) throw new IllegalArgumentException ("Empty range"); int maxSoFar 0; for (int i start; i K last; i f if (x[i] maxSoFar maxSoFar i; return maxSoFar

Explanation / Answer

MaxValueTest.java

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


public class MaxValueTest {

  
   public static void main(String[] args) {
       try{
       Scanner scan = new Scanner(new File("D:\inputData.txt"));
       Scanner scan1 = new Scanner(new File("D:\inputData.txt"));
       int count = 0;
       while(scan1.hasNextInt()){
           count++;
           scan1.nextInt();
       }
       int x[] = new int[count];
       count=0;
       while(scan.hasNextInt()){
           x[count] = scan.nextInt();
           count++;
       }
       MaxValueTest m = new MaxValueTest();
       System.out.println(m.findMax(x, 3, 7));
       System.out.println(m.findMax(x, 1, 7));
       System.out.println(m.findMax(x, 1, 5));
       }
       catch(FileNotFoundException e){
           System.out.println("Input file does not exist");
       }
       catch(IllegalArgumentException e){
           System.out.println(e);
       }
   }
   public int findMax(int[] x, int start, int last) throws IllegalArgumentException {
       if(start> last ){
           throw new IllegalArgumentException("Empty range");
       }
       int maxSoFar = x[start];
       for(int i=start; i<last; i++){
           if(x[i] > maxSoFar){
               maxSoFar = x[i];
           }
       }
       return maxSoFar;
   }
}

Output:

-1
-1
-42