在我们当前的章节中,我们使用的数组创建了一个列表,以便从另一个类中调用列表。从另一个类中显示多个数组列表
目标:显示来自另一个类的并行数组,这可以是单数或组。
问题:调用具有不同数据类型的多并行数组的最佳或有效方法?
错误:以非法声明开始,如先前在此处指示的是整个代码,请忽略我刚测试的循环显示以确保阵列安装正确。
谢谢大家,再一次的任何援助深表感谢
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