public static void main(String[] args) {
Scanner s = new Scanner(System.in);
final int STUDENT_SIZE = 50;
int i = 0;
char choice1 = 'y';
String [] stdntName = new String [50];
String [] WIDNUM = new String [STUDENT_SIZE];
int [] EXM1 = new int [STUDENT_SIZE];
int [] EXM2 = new int [STUDENT_SIZE];
int [] EXM3 = new int [STUDENT_SIZE];
int [] finalExm = new int [STUDENT_SIZE];
for (i=0; i < stdntName.length; i++) {
System.out.print("Please enter the name of Student " + (i+1) + ": ");
stdntName[i] = s.nextLine();
System.out.println("Please enter the WID of Student " + (i+1) + ": ");
WIDNUM[i] = s.nextLine();
if (WIDNUM[i].length() != 9 ) {
System.out.println("**Invalid WID...must be 9-digits");
System.out.println("Please re-enter score:");
WIDNUM[i] = s.nextLine();
}
System.out.println("Please enter score for Exam 1: ");
EXM1[i] = s.nextInt();
if (EXM1[i] < 0 || EXM1[i] > 50) {
System.out.println("**Invalid score...please enter 0-50 only");
System.out.println("Please re-enter score: ");
EXM1[i] = s.nextInt();
}
System.out.println("Please enter score for Exam 2 ");
EXM2[i] = s.nextInt();
if (EXM2[i] < 0 || EXM2[i] > 50) {
System.out.println("**Invalid score...please enter 0-50 only");
System.out.println("Please re-enter score: ");
EXM2[i] = s.nextInt();
}
System.out.println("Please enter score for Exam 3 ");
EXM3[i] = s.nextInt();
if (EXM3[i] < 0 || EXM3[i] > 50) {
System.out.println("**Invalid score...please enter 0-50 only");
System.out.println("Please re-enter score: ");
EXM3[i] = s.nextInt();
}
System.out.println("Please enter score for Final Exam ");
finalExm[i] = s.nextInt();
if (finalExm[i] < 0 || finalExm[i] > 100) {
System.out.println("**Invalid score...please enter 0-100 only");
System.out.println("Please re-enter score: ");
finalExm[i] = s.nextInt();
}
System.out.print("Do you wish to enter another? (y/n): ");
choice1 = s.nextLine().toLowerCase().charAt(0); // read entire line
if (choice1 != 'y') {
break;
}
}
}
}
This is the error message:
Do you wish to enter another? (y/n): Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48) at java.base/java.lang.String.charAt(String.java:712) at Proj4.main(Proj4.java:77)