Skip to content

Instantly share code, notes, and snippets.

@maciekmm
Created January 25, 2015 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciekmm/ba5f10a7fd4ed6143126 to your computer and use it in GitHub Desktop.
Save maciekmm/ba5f10a7fd4ed6143126 to your computer and use it in GitHub Desktop.
package net.maciekmm;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
public class Drawer {
public enum Clazz {
GEO, HISTORY, SOCIETY
}
private static final ArrayList<Student> students = new ArrayList<>(30);
public static void main(String[] args) {
//Load students
new Drawer(Clazz.GEO, 2, 50).draw();
new Drawer(Clazz.HISTORY, 1, 50).draw();
new Drawer(Clazz.SOCIETY, 1, 50).draw();
}
private final int lessons;
private final int studentsPerLesson;
private final Clazz clazz;
public Drawer(Clazz clazz, int studentsPerLesson, int lessons) {
this.studentsPerLesson = studentsPerLesson;
this.lessons = lessons;
this.clazz = clazz;
}
public void draw() {
System.out.println("Starting draw for " + clazz);
Collections.shuffle(students);
int studs = 0;
for (int lesson = 0; lesson < lessons; lesson++) {
System.out.println("Lesson: " + (lesson + 1));
int drew = 0;
while (drew != studentsPerLesson) {
Student student = students.get(studs);
if (!student.hasBeenQuestioned(clazz)) {
drew++;
System.out.println(" " + student.getId());
}
studs++;
if (studs + 1 == students.size()) {
flipQuestionedStatus();
break;
}
}
}
}
private void flipQuestionedStatus() {
Collections.shuffle(students);
for (Student student : students) {
student.setQuestioned(clazz, !student.hasBeenQuestioned(clazz));
}
}
public static class Student {
private final String id;
private HashMap<Clazz, Boolean> questioned = new HashMap<>();
public Student(String id) {
this.id = id;
}
public String getId() {
return id;
}
public void setQuestioned(Clazz clazz, boolean questioned) {
this.questioned.put(clazz, questioned);
}
public boolean hasBeenQuestioned(Clazz clazz) {
return this.questioned.get(clazz);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment