Problem Statement The following method does not appear to be
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.
Please do the following in this order:
In your code, you also need to include a brief description of your debugging plan as a series of comments that proceeds the method definition.
In order to properly debug the given method, you need to make sure that you have several print statements at various execution phases to ensure a better insight of how the given code work. After finishing the debugging the method and fixing the problem, you need to leave ALL debugging statements in, but execute them only when the global constant TESTING is true.
Before uploading your code. Make sure that it works properly for ANY combinations of input parameters and for all boundary conditions.
(file data)
inputData.txt
-15
-57
-75
-93
-42
-1
-9
-63
-77
-12
Solution
Hi, I wrote Driver class.
You can test with any combination of integre from file inputData.txt.
public class Test {
/*
*
* Problem of this method is : when all numbers are negative then it always return 0,
* since 0 is greater than all negative number
*/
public static int findMax(int[] x, int start, int last){
if(start > last)
throw new IllegalArgumentException(\"Empty range\");
int maxSoFar = 0;
for(int i=start; i<last; i++){
if(x[i] > maxSoFar)
maxSoFar = x[i];
}
return maxSoFar;
}
public static void main(String[] args) throws FileNotFoundException{
// creating FIleReader and Buffered reader
Scanner readFile = new Scanner(new File(\"inputData.txt\"));
int arr[] = new int[50];
int start = 0;
int count = 0;
// reading all integers from file
while(readFile.hasNext()){
arr[start++] = readFile.nextInt();
}
count = start;
// finding max element
int max = findMax(arr, 0, count);
System.out.println(max);
}
}
Please let me know in case of any case

