Write a program that uses the following arrays: empld: an array of seven long in
ID: 3778225 • Letter: W
Question
Write a program that uses the following arrays: empld: an array of seven long integers to hold employee identification numbers. The array should be initialized with the following numbers: hours: an array of seven integers to hold the number of hours worked by each employee pay Rate: an array of seven double s to hold each employee's hourly pay rate wages: an array of seven double s to hold each employee's gross wages The program should relate the data in each array through the subscripts. For example, the number in element 0 of the hours array should be the number of hours worked by the employee whose identification number is stored in element 0 of the empld array That same employee's pay rate should be stored in element 0 of the pay Rate array. The program should display each employee number and ask the user to enter that employee's hours and pay rate. It should then calculate the gross wages for that employee (hours times pay rate) and store them in the wages array After the data has been entered for all the employees, the program should display each employee's identification number and gross wages. Input Validation: Do not accept negative values for hours or numbers less than 15.00 for pay rate.Explanation / Answer
Hi, Please find my implementation.
please let me know in case of any issue.
import java.util.Scanner;
public class Payroll {
public static void main(String[] args) {
// creating 4 arrays
String[] empId = {"5658845", "4520125", "7895122",
"8777541", "8451277", "1302850", "7580489"};
int[] hours = new int[7];
double[] payRate = new double[7];
double[] wages = new double[7];
Scanner sc = new Scanner(System.in);
// getting input
for(int i=0; i<7; i++){
System.out.println("Enter detais for employee #"+empId[i]+":");
System.out.print("hours worked: ");
hours[i] = sc.nextInt();
System.out.print("Pay Rate: ");
payRate[i] = sc.nextDouble();
}
// calculating wages
for(int i=0; i<7; i++)
wages[i] = hours[i]*payRate[i];
// displaying info
for(int i=0; i<7; i++){
System.out.println("Employee #"+empId[i]+" wage: "+wages[i]);
}
}
}
/*
Sample run:
Enter detais for employee #5658845:
hours worked: 22
Pay Rate: 43.54
Enter detais for employee #4520125:
hours worked: 43
Pay Rate: 45
Enter detais for employee #7895122:
hours worked: 39
Pay Rate: 46.5
Enter detais for employee #8777541:
hours worked: 40
Pay Rate: 54.34
Enter detais for employee #8451277:
hours worked: 42
Pay Rate: 44.3
Enter detais for employee #1302850:
hours worked: 56
Pay Rate: 50
Enter detais for employee #7580489:
hours worked: 47
Pay Rate: 30.8
Employee #5658845 wage: 957.88
Employee #4520125 wage: 1935.0
Employee #7895122 wage: 1813.5
Employee #8777541 wage: 2173.6000000000004
Employee #8451277 wage: 1860.6
Employee #1302850 wage: 2800.0
Employee #7580489 wage: 1447.6000000000001
*/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.