So for this program I need to have three arrays accept data and display the gross pay, It seems to work at first but after enter the first person's data, my code begins to stack on top of itself in the window, please help me fix this to work properly.
I am required to use arrays. Objects are not allowed.
import java.util.Scanner;
public class ThreeArrays {
public static void main(String args[]) {
float[] payRate = new float[5];
float[] hours = new float[5];
String[] name = new String[5];
getPayData(name, hours, payRate);
displayGrossPay(name, hours, payRate);
}
public static void getPayData(String[] name, float[] hours, float[] payRate) {
Scanner kb = new Scanner(System.in);
for (int i = 0; i < hours.length; i++) {
System.out.print("Enter the employee's name: ");
name[i] = kb.nextLine();
System.out.print("Enter the employee's hours: ");
hours[i] = kb.nextFloat();
System.out.print("Enter the employee's hourly rate: ");
payRate[i] = kb.nextFloat();
}
}
public static void displayGrossPay(String[] name, float[] hours, float[] payRate) {
for (int i = 0; i < hours.length; i++) {
System.out.println("Employee name: " + name[i] + " Gross Pay: " + hours[i] *
payRate[i]);
}
}
}