I've looped an array so firstly it grabs from inputted data full name and splits it to lname and fname, then with a loop inside that loop it sums scores you input.
When you end the second loop the first loop then asks for String.split (in my case fullname) again, but it doesn't allow me to input a new data to split instead gives the error "java.lang.ArrayIndexOutOfBoundsException: 1" and highlights "String fname = parts[1];
Any ideas, anything to help me get on the right track would be appreciated!
I've also tried
string = "";
string = null;
Here is my Code so far:
import java.util.Scanner;
public class TestScores
{
public static void main(String[] args) {
Scanner kb = new Scanner (System.in);
String fullname;
int sum = 0;
int count = 0;
int score;
System.out.println("Please enter name here e.g lastname, firstname");
fullname = kb.nextLine( );
while (fullname.equals ("Done") !=true){
String[] parts = fullname.split(",");
String lname = parts[0];
String fname = parts[1];
System.out.println("Enter scores (Type -1 to finish scoring.");
score = kb.nextInt();
while(score != -1)
{
sum += score;
score = kb.nextInt();
count++;
}
System.out.println(fname + " " + lname + "'s total Score is: " + sum);
System.out.println();
System.out.println("Please enter another name here e.g lastname, firstname to start scoring");
fullname = kb.nextLine( );
}
}
}