Stuck at a point in my assignment and need some help figuring it out. Here is wh
ID: 644103 • Letter: S
Question
Stuck at a point in my assignment and need some help figuring it out. Here is what code i have and below the code is what is supposed to be.
public static void main(String[] args) {
int[] myArray = {-3, -1, 5, 10, 3, 17, 2};
maxIndex(myArray);
}
/**
* This method determines the maximum value at the index
*
* @param myArray
*/
public static void maxIndex(int myArray[]) {
if (myArray.length < 1) {
System.out.println("[]");
return;
}
int[] newArray = new int[myArray.length - 1];
int maxIndex = getIndexFormat(myArray);
for (int i = 0, j = 0; i < myArray.length; i++, j++) {
if (i != maxIndex) {
newArray[j] = myArray[i] - 1;
} else {
j--;
}
}
getIndexFormat(newArray);
}
/**
* This method gets the index format of the maximum value
* @param myArray
* @return
*/
public static int getIndexFormat(int myArray[]) {
int max = myArray[0];
int index = 0;
System.out.print("[");
for (int i = 0; i < myArray.length; i++) {
if (myArray[i] > max) {
max = myArray[i];
index = i;
}
System.out.print(i + ":" + myArray[i] + ", ");
}
System.out.println("]");
System.out.println("Maximum value " + max + " found at index " + index);
return index;
}
}
uses two files located in the root/default directory of your NetBeans project an input/output file called numberList.txt and an output/append file called maximumsList.txt. These files will contain only integers, one integer per line. Note: you will want to close numberList.txt from input before you attempt to use it for output.
For initial testing, create the file numberList.txt with the following values: 3, -1, 5, 10, 3, 17, 2.
read a list of integers from the input file and store them in an integer array. Construct your program so that it will work with any set (and number of) integers. If the input file is empty, then the program should indicate that the file is empty with an appropriate message and halt. Identify the maximum value in the list and output it (with appropriate descriptive output text) to the console.
overwrite the input file with the same values that were originally found in the file, in the same order, with only one change