Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement