Advertisement
VincentOostelbos

Classes scheduler problem

Sep 8th, 2014
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.40 KB | None | 0 0
  1. public class Scheduler {
  2.     static Random rand = new Random();
  3.    
  4.     public static void main(String args[]) {
  5.         List<Slot> slots = new ArrayList<Slot>(); // Create timeslot List
  6.         Slot slotm1 = new Slot("M1"); // Create timeslot (parameter: identifier = M/T/W/H/F for day of week, hour number)
  7.         Slot slotm2 = new Slot("M2"); // Create timeslot
  8.         // More slots
  9.         slots.addAll(Arrays.asList(slotm1,slotm2)); // Add slots to List
  10.  
  11.         List<Course> courses = new ArrayList<Course>(); // Create courses List
  12.         Course biologyI = new Course("biology I",2,slots); // Create course (parameters: name, number of slots per week, slots List)
  13.         Course chemistryI = new Course("chemistry I",2,slots); // Create course
  14.         Course civsocI = new Course("civics & society I",2,slots); // Create course
  15.         // More courses
  16.  
  17.         courses.addAll(Arrays.asList(biologyI,chemistryI,civsocI); // Actually
  18.  
  19.         List<Student> students = new ArrayList<Student>(); // Create students List
  20.         List<Course> studentCourses = new ArrayList<Course>(); // Create temporary storage for student courses
  21.  
  22.         studentCourses.addAll(Arrays.asList(biologyI,civsocI)); // Add courses relevant to student
  23.         Student nicolaos = new Student("Nicolaos Haakonsson",studentCourses,slots,0); // Create student
  24.  
  25.         studentCourses.clear(); // Clear temporary storage for student courses
  26.         studentCourses.addAll(Arrays.asList(biologyI,chemistryI)); // Add courses relevant to student
  27.         Student hide = new Student("Hide Tosell",studentCourses,slots,1); // Create student
  28.  
  29.         // More students
  30.  
  31.         students.addAll(Arrays.asList(nicolaos,hide)); // Add students to list
  32.  
  33.         Student randStudent = students.get(rand.nextInt(students.size()));
  34.         System.out.println("The following courses have been found for student " + randStudent.getName() + ": ");
  35.         for(int i=0; i<randStudent.getCourses().size(); i++) { // Cycle through all courses stored in student's courses List
  36.             System.out.print(randStudent.getCourses().get(i).getName()); // Get name of course i
  37.             if(i < randStudent.getCourses().size()-1) System.out.print(", "); // For readability
  38.         }
  39.     }
  40. }
  41.  
  42. public class Course {
  43.     private Random rand = new Random();
  44.     private List<Student> students = new ArrayList<Student>(); // List storing students attending this course (unused in segment)
  45.     List<Slot> slots = new ArrayList<Slot>(); // List containing all possible timeslots
  46.    
  47.     private String name;
  48.     private int points;
  49.    
  50.     // Constructor
  51.     public Course(String name, int points, List<Slot> slots) {
  52.         this.name = name;
  53.         this.points = points;
  54.         this.slots = slots;
  55.     }
  56.  
  57.     public String getName() {
  58.         return name;
  59.     }
  60. }
  61.  
  62. public class Student {
  63.     private String name;
  64.     private List<Course> courses = new ArrayList<Course>(); // List storing courses attended by this student
  65.     List<Slot> freeslots = new ArrayList<Slot>(); // List storing slots still available (unscheduled) for student (unused in segment)
  66.     private int studentnr; // Student identifier
  67.  
  68.     // Constructor
  69.     public Student(String name, List<Course> courses, List<Slot> slots, int studentnr) {
  70.         this.name = name;
  71.         this.freeslots = slots;
  72.         this.courses = courses;
  73.         this.studentnr = studentnr;
  74.     }
  75.    
  76.     // courses getter
  77.     public List<Course> getCourses() {
  78.         return courses;
  79.     }
  80.    
  81.     // name getter
  82.     public String getName() {
  83.         return name;
  84.     }
  85. }
  86.  
  87.  
  88. /*
  89. * Output given:
  90. *
  91. * The following courses have been found for student Nicolaos Haakonsson:
  92. * biology I, chemistry I
  93. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement