私たちは現在の章で、別のクラスから呼び出されるリストを作成する際に問題がある配列を使用しています。別のクラスから複数の配列リストを表示
目標:別のクラスの並列配列を表示します。これは、単数形でもグループ内でもかまいません。
質問:さまざまなデータ型のマルチパラレルアレイを呼び出すには最高の効率的な方法がありますか?
エラー:以前にここに指示されたとおり、違法な文で始まるコード全体で、私はちょうど配列が正しくセットアップしたことを確認するためにテストしていたループ表示を無視してください。
みんなありがとう、またしてもどのような援助が大幅に
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つの表示方法、String、Int、Double ...を意味する – Elements
@Ousmane命令は、配列を持つクラスを作成すると言う:従業員ID、First、Last、Wage、Skill。別のクラスを作成し、情報を表示します。 – Elements