Respuesta :
Answer:
import java.util.Scanner;
public class Salary
{
public static void main(String[] args) {
int numberOfEmployees;
double payRate, numberOfHours, totalPay = 0;
Scanner input1 = new Scanner(System.in);
Scanner input2 = new Scanner(System.in);
System.out.print("Enter the number of employees: ");
numberOfEmployees = input1.nextInt();
for(int i=1; i<=numberOfEmployees; i++) {
System.out.print("Enter the pay rate for employee " + i + ": ");
payRate = input2.nextDouble();
System.out.print("Enter the number of hours worked: ");
numberOfHours = input2.nextDouble();
totalPay += (payRate * numberOfHours);
}
System.out.println("Total payment is: "+ totalPay);
}
}
Explanation:
- Declare the variables
- Ask the user the for the number of employees
- Inside the for loop, ask the user for pay rate and hours worked for each employee
- Calculate the total pay
- Outside of the loop, print the total pay
Answer:
# the user is prompt to enter the number of employees
number_of_employees = int(input("Enter number of employee: "))
# the total_salary is initialized to 0
total_salary = 0
# for loop that loop through the number of employees
# and calculate the salary for each by multiplying the rate & hour
for each_employee in range(number_of_employees):
employee_hour = int(input("Enter your worked hour: "))
employee_rate = int(input("Enter your rate: "))
employee_salary = employee_hour * employee_rate
# the total salary is gotten by adding it to employee salary
total_salary += employee_salary
# The total salary is displayed.
print("The total salary for the entire employee is: $", total_salary, sep="")
Explanation:
The program is written in Python and is well commented. An image for the program output when it is executed is attached.
