私はarraylistからランダムなオブジェクトを取得しようとしています。無作為は、変数が真であるとして入手可能なarraylistのオブジェクトの中にあるべきです。arraylist固有の変数からランダムオブジェクトを取得
今すぐ、アライリスト全体からランダムにアテンダントを得ます。
public static Attendant askForAtt() {
Scanner scanAtt = new Scanner(System.in);
Random randAtt = new Random();
//Attendant asnAtt = null;
System.out.println("Do you require an Attendant ? Y or N");
String response = scanAtt.next();
if ((response.equals("y")) || (response.equals("yes")) || (response.equals("Yes")) || (response.equals("Y"))) {
// Cars.setAssignedTo(myAtt.get(randAtt.nextInt(myAtt.size())));
return myAtt.get(randAtt.nextInt(myAtt.size()));
} else if ((response.equals("n")) || (response.equals("no")) || (response.equals("No")) || (response.equals("N"))) {
return new Attendant ("User");
}
return new Attendant ("User"); //If input is neither Yes nor No then return new Attendant
}
I型になっています何:
return myAtt.get(randAtt.nextInt(myAtt.size()));
このメソッドは次のとおりです。私はちょうど これは行がある、それは真(変数)であること参加者に制限を指定する必要がありますか? 私の乗務員はそのようなものです:
public Attendant(int staffNum, String id, boolean available, attNm name, Cars assign) {
this.staffNum = staffNum;
this.id = id;
this.available = available;
this.name = name;
this.assign = assign;
}
PS:私の英語のため申し訳ありません。それは可能性があり、あなたのアテンダントのクラスでは私の第三言語
**あなたはこれが何を意味するのですか**アテンダントが真(可変)であることを指定してください** –
私のアテンダントは真のパレオメータを持っています。 arraylistの中にはfalseがあります – Kavi
描画された出席者のために利用可能なフィールドをチェックし、falseの場合は別のものを描画します(whileループ) – porgo