2nd question! (followup to my first) I'm now trying to list the first array (namesArray) and match each index with the user-defined amount of hours in hoursArray. So it asks for how many people worked for the week, then asks for their names, then asks the hours each of those people worked (while displaying their names to the side for improved quality).
I keep getting an IndexOutOfBounds exception whenever I try to enter the first amount of hours worked by the first person, how do I fix this to take the amount of hours worked by each person correctly?
import java.util.Scanner;
import java.util.Arrays;
class Tips_Calc
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("How many employees for the week?: ");
int numberOfEmps = scan.nextInt();
int numberOfHours = 0;
System.out.println("\nEnter names of workers up to the entered amount (" + numberOfEmps + "):");
String[] namesArray = new String[numberOfEmps];
for(int i = 0; i < numberOfEmps; i++)
{
namesArray[i] = scan.next();
}
System.out.println("\nEnter the amount of hours each person worked for the week: ");
float[] hoursArray = new float[numberOfHours];
for(int n = 0; n < namesArray.length; n++)
{
int counter = 0; // <------ do i even need this variable?
System.out.print(namesArray[n] + ": ");
hoursArray[counter] = scan.nextFloat(); // <------ the error is here!
System.out.println("\n");
counter++;
}
}
}