fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class ThreeArrays {
  8.  
  9. public static void main(String args[]) {
  10. float[] payRate = new float[5];
  11. float[] hours = new float[5];
  12. String[] name = new String[5];
  13.  
  14. getPayData(name, hours, payRate);
  15.  
  16. displayGrossPay(name, hours, payRate);
  17. }
  18.  
  19. public static void getPayData(String[] name, float[] hours, float[] payRate) {
  20. Scanner kb = new Scanner(System.in);
  21.  
  22. for (int i = 0; i < hours.length; i++) {
  23.  
  24. System.out.print("Enter the employee's name: ");
  25. name[i] = kb.nextLine();
  26.  
  27. System.out.print("Enter the employee's hours: ");
  28. hours[i] = kb.nextFloat();
  29.  
  30. System.out.print("Enter the employee's hourly rate: ");
  31. payRate[i] = kb.nextFloat();
  32.  
  33. if(i < hours.length-1) kb.next();
  34. }
  35.  
  36. }
  37.  
  38. public static void displayGrossPay(String[] name, float[] hours, float[] payRate) {
  39. for (int i = 0; i < hours.length; i++) {
  40. System.out.println("Employee name: " + name[i] + " Gross Pay: " + (hours[i] *
  41. payRate[i]));
  42. }
  43. }
  44. }
Success #stdin #stdout 0.14s 31380KB
stdin
Name 1
12.0 13.0
Name 1
12.0 13.0
Name 1
12.0 13.0
Name 1
12.0 13.0
Name 1
12.0 13.0
stdout
Enter the employee's name: Enter the employee's hours: Enter the employee's hourly rate: Enter the employee's name: Enter the employee's hours: Enter the employee's hourly rate: Enter the employee's name: Enter the employee's hours: Enter the employee's hourly rate: Enter the employee's name: Enter the employee's hours: Enter the employee's hourly rate: Enter the employee's name: Enter the employee's hours: Enter the employee's hourly rate: Employee name: Name 1 Gross Pay: 156.0
Employee name:  1 Gross Pay: 156.0
Employee name:  1 Gross Pay: 156.0
Employee name:  1 Gross Pay: 156.0
Employee name:  1 Gross Pay: 156.0