我在获取数组中整数的总和时遇到问题,并且在获取整数 * 1.5 的乘积时遇到问题。我下面的代码可能完全关闭,因为我是 Java 新手,并且已经使用了几个小时。该程序的目的是输入每天工作 5 天的小时数。有了这个和工资率,你应该输出平均工作时间、总小时数和总工资。工资还应包括加班(如果有的话)。任何帮助,将不胜感激。
String name;
String id;
int payRate;
int[] hours = new int[5];
int avgHours;
int totalPay;
int totalHours = 0;
int counter;
int overTime = 0;
//housekeeping
System.out.print("Enter the Employee's name: ");
inputString = input.readLine();
name = inputString;
System.out.print("Enter the Employee's ID: ");
inputString = input.readLine();
id = inputString;
System.out.print("Enter the Employee's pay rate: ");
inputString = input.readLine();
payRate = Integer.parseInt(inputString);
//hoursPay
counter = 0;
for(hours[counter] = 0; counter < 5; counter++)
{
System.out.print("How many hours did the employee work? ");
inputString = input.readLine();
hours[counter] = Integer.parseInt(inputString);
}//endfor
for(totalHours = 0; counter < 5; hours[counter]++);
{
totalHours += hours[counter];
if(totalHours > 40)
{
overTime = payRate + (payRate / 2);
}//endif
}//endwhile
//print
if(counter == 5)
{
System.out.println(name + " " + id + " $" + payRate + "/hour" );
avgHours = totalHours / counter;
totalPay = totalHours * payRate + overTime;
System.out.println...
System.out.println...
System.out.println...