Array list usage
I keep getting the following error:
java.lang.ArrayIndexOutOfBoundsException: 9
at JayScout.option2(JayScout.java:99)
at JayScout.main(JayScout.java:46)
the code is supposed to accept 10 user entries, with each entry consisting of the following data: name, age, position and average
after accepting the data, the program should sort the entries based on age. After sorting, it should only display the records where age < 25 and the average > 0.280
here is the program code
import java.awt.*;
import hsa.Console;
publicclass JayScout
{
static Console c;// The output console
static String n[] =new String[9];
staticint o[] =newint[9];
static String p[] =new String[9];
staticdouble a[] =newdouble[9];
staticint x;
publicstaticvoid main (String[] args)
{
c =new Console ();
int choice;
c.println("Blue Jay Scout Program\n");
do
{
c.println("\n\n\t\tProgram Menu\n");
c.println("\t\t 1. Store Information");
c.println("\t\t 2. Possible Drafts");
c.println("\t\t 3. Exit");
do
{
c.print ("\n\nWhat is your choice (1-3): ");
choice = c.readInt ();
if ((choice < 1) || (choice > 3))
{
c.setTextColor(Color.red);
c.println ("\nInvalid ... enter 1-3 only\n");
c.setTextColor(Color.black);
}
}
while ((choice < 1) || (choice > 3));
switch (choice)
{
case 1: option1();break;
case 2: option2();break;//this is also highlighted by debugger
}
}
while (choice != 3);
c.println("\n\nBye");
// Place your program here. 'c' is the output console
}// main method
publicstaticvoid option1()
{
c.println("Information Storage\n");
for (x=0;x<9;x++)
{
c.print("\nEnter Player Name - ");
n[x] = c.readLine();
c.print("Enter Player Age - ");
o[x] = c.readInt();
c.print("Enter Player Position - ");
p[x] = c.readLine();
c.print("Enter Batting Average - ");
a[x] = c.readDouble();
}
int y;
int temp;
temp = 0;
for (x = 0; x >= 8; x++)
{
for (y = 0; y <=8-x; y++)
{
if (o[y] > o[y + 1])
{
temp = o[y];
o[y] = o[y + 1];
o[y + 1] = temp;
}
}
}
}
publicstaticvoid option2()
{
c.println("Draft Possibilities\n");
c.println("NAME AGEPOSITIONAVERAGE");
for (x = 0; x<=9; x++)
{
if ((o[x]<25)&&(a[x]>=0.280))// this is where the Debugger pointed out the error is
//so the error is here but i dont know how to fix it
{
c.println(n[x]+""+o[x]+""+p[x]+" "+a[x]);
}
}
}
}

