So I have to write a simple program for homework that adds together different grades and then finds the students with the min and max grade using a different class and a constructor. I have everything working except the findMin method. It always returns 0, the findMax method works correctly though. I feel like I'm missing something simple, but not quite sure what it is. Any help would be appreciated, thanks.
Here is what I have:
import java.util.Scanner; import java.util.Arrays; class ScanArray { private static int[] finalArray = null; private static int minGrade = 0, maxGrade = 0, arrayNumberMax = 0, arrayNumberMin = 0; public ScanArray(int[] array) { finalArray = array; } public static void findMax() { for (int i = 0; i < finalArray.length; i++) { if (maxGrade < finalArray[i]) { maxGrade = finalArray[i]; arrayNumberMax = i; } } System.out.println("The highest score is: " + maxGrade + "/300, which is student number " + arrayNumberMax + "."); } public static void findMin() { for (int i = 0; i < finalArray.length; i++) { if (minGrade > finalArray[i]) { minGrade = finalArray[i]; arrayNumberMin = i; } } System.out.println("The lowest score is: " + minGrade + "/300, which is student number " + arrayNumberMin + "."); } } class Assign7_Sniffin { public static int [] termType, midTerm_1 = new int[10], midTerm_2 = new int[10], finalExam = new int[10], allGrades = new int[10]; public static int termInput; public static String termName; public static void main(String[] args) { //Process the input of grades for (int i = 0; i <= 2; i++) { termInput = i; inputTypes(); } //Add the grades together and find min and max using scanarray class addGrades(); ScanArray grades = new ScanArray(allGrades); ScanArray.findMax(); ScanArray.findMin(); } //Switch terms public static void inputTypes() { switch (termInput) { case 0: termName = "Midterm 1"; termType = midTerm_1; break; case 1: termName = "Midterm 2"; termType = midTerm_2; break; case 2: termName = "Final exam"; termType = finalExam; break; default: System.out.println("Error in term type."); } gatherArray(); System.out.print(termName + " grades: "); System.out.println(Arrays.toString(termType)); } public static void gatherArray() { try { Scanner input = new Scanner(System.in); for (int i = 0; i < termType.length; i++) { System.out.print("Enter " + termName + " grade for student number " + i + ": "); termType[i] = input.nextInt(); } } catch(Exception e) { System.out.println("Invalid input."); } } private static void addGrades() { for (int i = 0; i < allGrades.length; i++) { allGrades[i] = (midTerm_1[i] + midTerm_2[i] + finalExam[i]); } } }