问题是创建一个程序,要求用户输入多少员工。然后对于每个员工,输入姓名、小时工资率、工作小时数。计算员工工资、加班费和总工资的结果。
我的困境是如何找到所有工资的总和。所有员工工资、所有员工加班工资和所有员工总工资
前任。用户输入: 2 名员工(创建两个数组) 将输入两个输入(姓名、费率、工作小时数) 将计算
两个结果(工资、加班费、总工资) 如何将工资、加班费和总工资相加来自两个员工?
这是我想出的代码,但它需要工作
导入 java.util.Scanner;
public class paycheck {
public static void main(String[] args)
{
Scanner input= new Scanner(System.in);
System.out.print("Enter number of Employees: ");
int numberOfEmp= input.nextInt();
int[] arrayList= new int[numberOfEmp];
for (int i = 0; i < arrayList.length; i++){
System.out.print("Enter Employee Name: ");
String empName= input.next();
System.out.print("Enter hourly rate: ");
int rate= input.nextInt();
System.out.print("Enter hours worked: ");
int hours=input.nextInt();
if (hours >=40)
{
double regPay= hours * rate;
double otPay = (hours-40) *(rate*1.5);
double totalPay= regPay + otPay;
System.out.print("\nEmployee name: " + empName+"\n Regular pay: " + regPay +"\n Overtime pay: " + otPay+ "\n Total pay: " + totalPay+ "\n"+ "\n");
}
else
{
double regPay= hours * rate;
double otPay =0;
double totalPay= regPay + otPay;
System.out.print("\nEmployee name: " + empName+ "\n Regular pay: " + regPay +"\n Overtime pay: " + otPay+ "\n Total pay: " + totalPay+ "\n"+ "\n");
}
}
}
}