If you see in the code below where I print "Would you like to use previous key" I need to be able to save the previous key answers to be used again.. not sure how to go about doing this..
import java.util.Scanner; public class Main { public static void main(String[] args) { String[] studentName = new String[20]; int[] studentAverage = new int[20]; Scanner input = new Scanner(System.in); int numberOf = 0; int sub = 0; int x = 0; int highest = 0; int averageHolder = 0; String[] answers; String[] correct; int whichStudent = 0; int timesRan = 0; String AvToOr, letterGrade, stuNameAsk, goOn, sameKey, topStudent = null, keyRem; while (x == 0) { whichStudent = sub; if (timesRan >= 1) { System.out .println("Would you like to use the same key as the previous one entered? Y for yes and N for no (Case does not matter)."); keyRem = input.next(); if (keyRem.equalsIgnoreCase("y")) { System.out.println(); } else if (keyRem.equalsIgnoreCase("n")) { } } System.out .println("Enter student name. (Current limit of amount of students is 20.)"); stuNameAsk = input.next(); studentName[sub] = stuNameAsk; System.out .println("How many questions would you like to input? (Maximum is infinite.)"); int num = input.nextInt(); // get the number of times to ask answers = new String[num]; // student's answers correct = new String[num]; // for teachers for (int x1 = 0; x1 < num; x1++) { System.out .println("Enter the answer for question number: " + (x1 + 1) + ". Answer types are A,B,C,D,E, etc. Case does not matter."); correct[x1] = input.next(); } System.out.println("Now for the students."); for (int x1 = 0; x1 < num; x1++) { System.out .println("Enter the student answer for question number: " + (x1 + 1)); answers[x1] = input.next(); } int average = 0; // his/her grade for (int x1 = 0; x1 < num; x1++) if (correct[x1].equalsIgnoreCase(answers[x1])) average++; average = (int) (((double) average) / ((double) num) * 100); studentAverage[sub] = average; System.out.println(studentName[0 + whichStudent] + "'s grade is " + studentAverage[0 + whichStudent] + "%"); System.out .println("Do you want to enter another student? Type Y for yes and N for no."); goOn = input.next(); if (goOn.equalsIgnoreCase("n")) { x++; } else if (goOn.equalsIgnoreCase("y")) { sub++; timesRan++; } else { System.out .println("Your answer is not valid. Please try again."); System.out.println("Do you want to enter another student?"); goOn = input.next(); if (goOn.equalsIgnoreCase("n")) { x++; } else if (goOn.equalsIgnoreCase("y")) { sub++; timesRan++; } else { System.out .println("Your answer is not valid. Program restarted."); } } } System.out.println("All entered students and their averages:"); for (int varTest = 0; varTest <= timesRan; varTest++) { System.out.println(""); System.out.println(studentName[varTest] + "'s average is " + studentAverage[varTest] + "%"); } System.out.println(""); System.out .println("Would you like to (A)verage, find the (top) grade, or (end) the program? (Case does not matter)"); AvToOr = input.next(); if (AvToOr.equalsIgnoreCase("A")) { for (int varTest = 0; varTest <= timesRan; varTest++) { averageHolder = averageHolder + studentAverage[varTest]; } System.out.println(averageHolder / (timesRan + 1) + "%" + " is the average of all the students entered."); } else if (AvToOr.equalsIgnoreCase("top")) { for (int index = 0; index <= timesRan; index++) { if (studentAverage[index] > highest) highest = studentAverage[index]; } for (int tester = 0; tester <= timesRan; tester++) { if (studentAverage[tester] == highest) { topStudent = studentName[tester]; tester = timesRan++; } else { } } System.out.println(topStudent + " had the highest grade with a " + highest + "%"); } else if (AvToOr.equalsIgnoreCase("end")) { } } }