我想分裂我的變量,並輸入我的學生數據,所以我可以繼續我的成績計算程序,但我第二次分裂輸入的字符串,有一個問題,我不能找出它的起因。麻煩分裂Java程序中的數據
用戶將輸入信息,看起來像這樣 約翰·丹佛:E100 Q70 Q50 H100 E100 E90 H80 Q60 H100
程序需要裂開所有這些數據,並得到進入到一個數組名,然後是輸入數據中的「e」,「q」或「h」代表的考試分數,測驗分數和家庭作業分數。
import java.util.Scanner;
public class GradeCalcWithArrays { /*
* Daniel The purpose is to calculate
* entered grades
*/
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
boolean done = false;
boolean quit = false;
int choice = 0;
int maxstudents = 200;
int[] examstats = new int[3]; /*
* Array created to store the information
* entered for exams
*/
int[] quizstats = new int[3]; /*
* Array created to store the information
* entered for quizzes
*/
int[] homeworkstats = new int[3]; /*
* Array created to store the
* information entered for homework
*/
String[] studentnames = new String[maxstudents]; /*
* Array created to
* store the student
* name information
* entered
*/
System.out.println("Welcome to GradeBook!");
System.out.println("Please provide grade item details");
System.out.print("Exams (number, points, weight):");
examstats[0] = s.nextInt(); // inputs exam number
examstats[1] = s.nextInt(); // inputs exam points
examstats[2] = s.nextInt(); // inputs exam weight
System.out.print("Quizzes (number, points, weight):");
quizstats[0] = s.nextInt(); // inputs quiz number
quizstats[1] = s.nextInt(); // inputs quiz points
quizstats[2] = s.nextInt(); // inputs quiz weight
System.out.print("Homework (number, points, weight):");
homeworkstats[0] = s.nextInt(); // inputs homework number
homeworkstats[1] = s.nextInt(); // inputs homework points
homeworkstats[2] = s.nextInt(); // inputs homework weight
double[] examscores = new double[examstats[0]];
double[] quizscores = new double[quizstats[0]];
double[] hwscores = new double[homeworkstats[0]];
System.out.println("--------------------");
do {
System.out.println("What would you like to do?");
System.out.println(" 1 Add student data");
System.out.println(" 2 Display student grades & statistics");
System.out.println(" 3 Plot grade distribution");
System.out.println(" 4 Quit");
System.out.print("Your choice:");
choice = s.nextInt(); /*
* Choice will determine what the next course of
* action will be with the program
*/
if (choice == 1) {
System.out.println("Enter student data:");
for (int i = 0; i <= maxstudents; i++) {
System.out.print("Data>");
String dataentry = s.nextLine();
String[] firstsplit = dataentry.split(":");
studentnames[i] = firstsplit[0];
String[] secondsplit = firstsplit[1].split(" ");
for (int j = 0; j <= maxstudents; j++) {
String c;
c = secondsplit[j].substring(0, 1);
if (c == "e") {
secondsplit = secondsplit[j].split("e");
examscores[i] = Double.parseDouble(secondsplit[j]);
}
if (c == "q") {
secondsplit = secondsplit[j].split("q");
quizscores[i] = Double.parseDouble(secondsplit[j]);
}
if (c == "h") {
secondsplit = secondsplit[j].split("h");
hwscores[i] = Double.parseDouble(secondsplit[j]);
}
if (dataentry.equals("done")) {
break;
}
}
}
}
if (choice == 2) {
}
if (choice == 3) {
}
if (choice == 4) {
quit = true;
System.out.println("Good bye!");
}
} while (quit == false);
}
}
我得到一個錯誤,指出:異常線程 「main」 java.lang.ArrayIndexOutOfBoundsException:1 在GradeCalcWithArrays.main(GradeCalcWithArrays.java:83)
有人可以幫助我解決這個問題並告訴我,如果我的程序正在工作?