2014-12-03 22 views
0

基本上,我的程序的重點是用戶輸入員工數量的工資程序,然後用相同數量的員工進行指示是什麼樣的員工,然後根據類型輸入員工信息。現在,我每次都要一個一個地從小時候開始。我設法得到我想要的輸出,直到完成while循環的條件繼續並輸出結果表格,但它不輸出結果並僅輸出列標籤。我決定使用for循環,以便它繼續顯示,直到達到大於大小的數字。我檢查了看我是否正在使用格式正確的數組[e] .method();但到目前爲止似乎沒有發現任何錯誤。通過引用其他方法的對象顯示數組值,不顯示for循環

它可能是參數不匹配的可能性或可​​能是濫用它嗎?

在此先感謝。

Scanner in = new Scanner(System.in); 
    System.out.println("Welcome to the Company's Payroll System!"); 
    System.out.println("Please enter the amount of employees in the company."); 
    int size = in.nextInt(); 
    Employee [] staff = new Employee [size]; 

    int i = 0; 

    while (i != staff.length) 
     { 

     System.out.println("Enter employee type (Choose Hourly, Salary, or Manager)"); 
     System.out.println("Press 4 to exit."); 
     String emptype = in.next(); 

    if (emptype.equalsIgnoreCase("Hourly")) 
    { 
     System.out.println("First name:"); 
     String first = in.next(); 

     System.out.println("Last name:"); 
     String last = in.next(); 

     System.out.println("Employee ID (7 digits):"); 
     Float identification = in.nextFloat(); 

     System.out.println("Job Title:"); 
     String title = in.next(); 

     System.out.println("Amount employee makes per hour: "); 
     double hour = in.nextDouble(); 

     staff [i] = new HourlyEmployee(first, last, identification, title, hour); 

     i++; 
    } 

     } 


     System.out.println("FIRST NAME \t LAST NAME \t ID \t JOB TITLE \t Weekly Salary"); 
     for (int e = 0; e > size; e++) 
     { 
     System.out.printf("%5d", staff[e].getfirstName() + staff[e].getlastName() + staff[e].getId() + staff[e].getTitle() + staff[e].weeklyPay());} 
     } 

}

回答

0

在for循環的條件是錯誤的。它應該是:

for (int e=0; e < size; e++)