java program Writejava program compile and test a program t
(java program )....Write(java program ) compile, and test a program that uses a loop to calculate and display each employee’s weekly pay and the accumulated total pay for the company. The program will first ask the user for the number of employees. It will then ask for the number of hours and rate of pay for each employee and display the calculated pay for each employee
Solution
EmployeePay.java
import java.util.Scanner;
public class EmployeePay {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println(\"Enter the number of employees: \");
int n = scan.nextInt();
int hours[] = new int[n];
double rate[] = new double[n];
for(int i=0; i<n; i++){
System.out.println(\"Enter Employee \"+(i+1)+\" details: \");
System.out.println(\"Enter the number of hours: \");
hours[i] = scan.nextInt();
System.out.println(\"Enter the pay rate: \");
rate[i] = scan.nextDouble();
}
double total = 0;
for(int i=0; i<n; i++){
double pay = hours[i] * rate[i];
total = total + pay;
System.out.println(\"Enter Employee \"+(i+1)+\" calculated pay: \"+pay);
}
System.out.println(\"Accumulated total pay for the company: \"+total);
}
}
Output:
Enter the number of employees:
3
Enter Employee 1 details:
Enter the number of hours:
40
Enter the pay rate:
100
Enter Employee 2 details:
Enter the number of hours:
50
Enter the pay rate:
200
Enter Employee 3 details:
Enter the number of hours:
45
Enter the pay rate:
150
Enter Employee 1 calculated pay: 4000.0
Enter Employee 2 calculated pay: 10000.0
Enter Employee 3 calculated pay: 6750.0
Accumulated total pay for the company: 20750.0

