Created
January 25, 2015 16:17
-
-
Save maciekmm/ba5f10a7fd4ed6143126 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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