Sunday, 18 August 2013

ArrayIndexOutOfBounds Exception on employee database program

ArrayIndexOutOfBounds Exception on employee database program

I am very new to java and have been trying to get my bearings with it.
I've been trying to write an proof of concept employee database. It all
works fine until I enter the last employee condition, then I get an
ArrayIndexOutOfBoundsException. Here is the code for both of my files. Any
help would be appreciated.
import java.util.Scanner;
public class EmployeeInterface
{
public static void main(String[] args)
{
Scanner Input = new Scanner(System.in);
System.out.println("Please enter the number of employees to
register.");
int employeeCount = Input.nextInt();
Employee.setEmployeeNumber(employeeCount);
String employeeFullName;
String employeeAddress;
String employeeDateOfHire;
for(int x = 0; x <= employeeCount; x++)
{
System.out.println("Please enter the full name of employee
number " + (x + 1));
Input.nextLine();
employeeFullName = Input.nextLine();
System.out.println("Please enter the address of employee
number " + (x + 1));
employeeAddress = Input.nextLine();
System.out.println("Please enter the date of hire for employee
" + (x + 1));
employeeDateOfHire = Input.nextLine();
Employee.employeeRegister(x, employeeFullName,
employeeAddress, employeeDateOfHire);
}
}
}
Here is the second file:
public class Employee
{
private static int employeeCount;
private static String employees[][] = new String[employeeCount][4];
public static void setEmployeeNumber(int x)
{
employeeCount = x;
}
public static void employeeRegister(int employeeNumber, String
employeeFullName, String address, String employeeHireDate)
{
employees[employeeNumber][0] = employeeFullName;
employees[employeeNumber][1] = employeeFullName;
employees[employeeNumber][2] = employeeFullName;
employees[employeeNumber][3] = employeeFullName;
}
}

No comments:

Post a Comment