我是學習java的新手,並且在按照書中的教程進行操作時,在線程「main」中收到此錯誤異常java.lang.ArrayIndexOutOfBoundsException:0 。我試圖從網絡上進行研究,找出有關錯誤的更多信息,但我找不到答案。更糟糕的是,當我試圖訪問他們的網站時,這本書的網站不再存在。線程「主」的異常java.lang.ArrayIndexOutOfBoundsException:0
該計劃是關於計算兩種類型的工人,工程師和技術人員的付款,包括爲兩名不同工人的原始工資的1.5倍的超時工資。 最高工作時間爲160小時,並且額外的小時數會觸發加班費率。
下面是我寫的代碼:
class PayCalculator3 {
public static void main (String []args) {
final int maxNoOverTime = 160;
final double engineerHourlyPay = 30;
final double technicianHourlyPay = 25.5;
final double overTimeRate = 1.5;
int position = Integer.parseInt(args[0]);
int hoursWorked = Integer.parseInt(args[1]);
double salary;
salary =
(position == 0) ?
// employee is an Engineer
(hoursWorked <= maxNoOverTime) ?
// he did not work overtime
(hoursWorked * engineerHourlyPay)
:
// he worked overtime
((maxNoOverTime * engineerHourlyPay) + ((hoursWorked - maxNoOverTime) * (engineerHourlyPay * overTimeRate)))
: (position == 1) ?
// if employee is a Technician
(hoursWorked <= maxNoOverTime) ?
// he did not work Overtime
(hoursWorked * technicianHourlyPay)
:
// he worked overtime
((maxNoOverTime * technicianHourlyPay) + ((hoursWorked - maxNoOverTime) * (technicianHourlyPay * overTimeRate)))
:
//Employee Type unknown
-1;
String str = (salary != -1) ?
("This month's salary >> $" + salary)
:
("Who the heck are you?");
System.out.println(str);
}
}
非常感謝您提前爲所有的你的幫助:)
您是如何調用該程序的?包括您輸入的實際命令行。你可以在'int position = Integer.parseInt(args [0]);'如果你沒有在命令行中包含任何參數。 – 2011-06-06 14:38:27