我有一个学校任务,我需要制作一个程序,自动让情侣在学校上课。在这种情况下,有 6 节课,每节课您都与不同的人合作。因此,在第 1 周 persona
与person 合作,b
接下来的几周他不能与 person 合作a
。
我编写了一些代码,将班级分成两部分,但我不知道如何每周改变这对夫妇。
这是我已经拥有的代码(抱歉不是英文):
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));
}