Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. package net.maciekmm;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Collections;
  5. import java.util.HashMap;
  6.  
  7. public class Drawer {
  8.  
  9. public enum Clazz {
  10.  
  11. GEO, HISTORY, SOCIETY
  12. }
  13.  
  14. private static final ArrayList<Student> students = new ArrayList<>(30);
  15.  
  16. public static void main(String[] args) {
  17.  
  18. //Load students
  19.  
  20. new Drawer(Clazz.GEO, 2, 50).draw();
  21. new Drawer(Clazz.HISTORY, 1, 50).draw();
  22. new Drawer(Clazz.SOCIETY, 1, 50).draw();
  23. }
  24.  
  25. private final int lessons;
  26. private final int studentsPerLesson;
  27. private final Clazz clazz;
  28.  
  29. public Drawer(Clazz clazz, int studentsPerLesson, int lessons) {
  30. this.studentsPerLesson = studentsPerLesson;
  31. this.lessons = lessons;
  32. this.clazz = clazz;
  33. }
  34.  
  35. public void draw() {
  36. System.out.println("Starting draw for " + clazz);
  37. Collections.shuffle(students);
  38. int studs = 0;
  39. for (int lesson = 0; lesson < lessons; lesson++) {
  40. System.out.println("Lesson: " + (lesson + 1));
  41. int drew = 0;
  42. while (drew != studentsPerLesson) {
  43. Student student = students.get(studs);
  44. if (!student.hasBeenQuestioned(clazz)) {
  45. drew++;
  46. System.out.println(" " + student.getId());
  47. }
  48. studs++;
  49. if (studs + 1 == students.size()) {
  50. flipQuestionedStatus();
  51. break;
  52. }
  53. }
  54. }
  55. }
  56.  
  57. private void flipQuestionedStatus() {
  58. Collections.shuffle(students);
  59. for (Student student : students) {
  60. student.setQuestioned(clazz, !student.hasBeenQuestioned(clazz));
  61. }
  62. }
  63.  
  64. public static class Student {
  65.  
  66. private final String id;
  67. private HashMap<Clazz, Boolean> questioned = new HashMap<>();
  68.  
  69. public Student(String id) {
  70. this.id = id;
  71. }
  72.  
  73. public String getId() {
  74. return id;
  75. }
  76.  
  77. public void setQuestioned(Clazz clazz, boolean questioned) {
  78. this.questioned.put(clazz, questioned);
  79. }
  80.  
  81. public boolean hasBeenQuestioned(Clazz clazz) {
  82. return this.questioned.get(clazz);
  83. }
  84.  
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement