学校でのレッスン用にカップルを自動的に作成するプログラムを作成する必要がある学校の課題があります。この場合、6 つのレッスンがあり、各レッスンで別の人とパートナーを組むことになります。そのため、1 週目は personとパートナーを組み、次の週は person とパートナーを組むことができませa
ん。b
a
クラスを 2 つに分割するコードをいくつか書きましたが、毎週カップルを変更する方法がわかりません。
これが私がすでに持っているコードです(英語ではなく申し訳ありません):
public void maakKoppels() {
if (leerlingenLijst.size() % 2 == 1) {
// if you have an odd number of students it adds the "Bye" student
leerlingenLijst.add(new Leerling("Bye"));
}
for (int i = 1; i <= 6; i++) {
//its needed for 6 lessons so it does it 6 times
maakKoppels(i, leerlingenLijst);
}
}
public void maakKoppels(int weekNum, ArrayList<Leerling> leerlingenLijst) {
int midden = leerlingenLijst.size() / 2; //split the arraylist in 2
ArrayList lijst1 = new ArrayList();
for (int j = 0; j < midden; j++) {
lijst1.add(leerlingenLijst.get(j));
}
ArrayList lijst2 = new ArrayList();
for (int j = leerlingenLijst.size() - 1; j >= midden; j--) {
lijst2.add(leerlingenLijst.get(j));
}
// here it fills the lessons with the 2 lists. weekNum is the lesson
// number and the name on lijst1 at index 0 couples with the name on
// lijst2 at index zero
practica.add(new Practicum(weekNum, lijst1, lijst2));
}