在我們當前的章節中,我們使用的數組創建了一個列表,以便從另一個類中調用列表。從另一個類中顯示多個數組列表
目標:顯示來自另一個類的並行數組,這可以是單數或組。
問題:調用具有不同數據類型的多並行數組的最佳或有效方法?
錯誤:以非法聲明開始,如先前在此處指示的是整個代碼,請忽略我剛測試的循環顯示以確保陣列安裝正確。
謝謝大家,再一次的任何援助深表感謝
import java.util.ArrayList;
public class Employee {
public static void main(String[] args) {
// create an array with employee number, first name, last name, wage, and Skill
int[] empID = {1001, 1002, 1003};
String[] firstName = {"Barry", "Bruce", "Selina"};
String[] lastName = {"Allen", "Wayne", "Kyle"};
double[] wage = {10.45, 22.50, 18.20};
String[] skill = {"Delivery Specialist", "Crime Prevention", "Feline Therapist"};
/*
for (int i = 0; i < empID.length; i++)
{
System.out.print("Employee ID: " + empID[i] + "\n");
System.out.print("First Name: " + firstName[i] + "\n");
System.out.print("Last Name: " + lastName[i] + "\n");
System.out.print("Hourly Wage: $" + wage[i] + "\n");
System.out.print("Skill: " +skill[i]);
System.out.println("\n");
}
*/
//create an object to be called upon from another class
public ArrayList<int, String, String, double, String> getEmployee() {
ArrayList<int, String, String, double, String> employeeList = new ArrayList<int, String, String, double, String>();
employeeList.add(empID);
employeeList.add(firstName);
employeeList.add(lastName);
employeeList.add(wage);
employeeList.add(skill);
return employeeList;
}
}
} //end of class
ArrayLists只能有**一個**類型參數。我建議將員工班級分開並提供相應的屬性。 –
哦所以使3顯示方法,字符串,詮釋,雙...有意義 – Elements
@Ousmane該指示說建立一個類與陣列:僱員ID,第一,最後,工資,技能。建立另一個班級並顯示信息。 – Elements