I need to call a method that returns an array of strings but I keep getting an error. I did the Arrays.toString but it still is not working.
public class MyStore {
public static void main(String[] args) {
SalesAssociate salesAssoc = new SalesAssociate("Bob", "Jones", "001");
System.out.println(Arrays.toString(salesAssoc.getCashPosition()));
}//main
}//class
This is my class and method.
public class SalesAssociate extends FloorAssociate {
// Constructor
public SalesAssociate(String firstName, String lastName, String employeeId) {
super(firstName, lastName, employeeId);
}
public String[] getCashPosition(){
String cp[] = new String[3];
cp[0]= super.getStoreLocation();
cp[1]= super.getEmployeeId();
cp[2]= "$3500";
cp[3]= timeStamp();
return cp;
}
}
And this is my error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 3
at indassn3.SalesAssociate.getCashPosition(SalesAssociate.java:38)
at indassn3.MyStore.main(MyStore.java:21)
Java Result: 1
By the way, the super.getStoreLocation, super.getEmployeeId, and timeStamp methods all return strings.
cp[3]is a 4th index. Just changenew String[3];tonew String[4];