Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Scheduler {
- static Random rand = new Random();
- public static void main(String args[]) {
- List<Slot> slots = new ArrayList<Slot>(); // Create timeslot List
- Slot slotm1 = new Slot("M1"); // Create timeslot (parameter: identifier = M/T/W/H/F for day of week, hour number)
- Slot slotm2 = new Slot("M2"); // Create timeslot
- // More slots
- slots.addAll(Arrays.asList(slotm1,slotm2)); // Add slots to List
- List<Course> courses = new ArrayList<Course>(); // Create courses List
- Course biologyI = new Course("biology I",2,slots); // Create course (parameters: name, number of slots per week, slots List)
- Course chemistryI = new Course("chemistry I",2,slots); // Create course
- Course civsocI = new Course("civics & society I",2,slots); // Create course
- // More courses
- courses.addAll(Arrays.asList(biologyI,chemistryI,civsocI); // Actually
- List<Student> students = new ArrayList<Student>(); // Create students List
- List<Course> studentCourses = new ArrayList<Course>(); // Create temporary storage for student courses
- studentCourses.addAll(Arrays.asList(biologyI,civsocI)); // Add courses relevant to student
- Student nicolaos = new Student("Nicolaos Haakonsson",studentCourses,slots,0); // Create student
- studentCourses.clear(); // Clear temporary storage for student courses
- studentCourses.addAll(Arrays.asList(biologyI,chemistryI)); // Add courses relevant to student
- Student hide = new Student("Hide Tosell",studentCourses,slots,1); // Create student
- // More students
- students.addAll(Arrays.asList(nicolaos,hide)); // Add students to list
- Student randStudent = students.get(rand.nextInt(students.size()));
- System.out.println("The following courses have been found for student " + randStudent.getName() + ": ");
- for(int i=0; i<randStudent.getCourses().size(); i++) { // Cycle through all courses stored in student's courses List
- System.out.print(randStudent.getCourses().get(i).getName()); // Get name of course i
- if(i < randStudent.getCourses().size()-1) System.out.print(", "); // For readability
- }
- }
- }
- public class Course {
- private Random rand = new Random();
- private List<Student> students = new ArrayList<Student>(); // List storing students attending this course (unused in segment)
- List<Slot> slots = new ArrayList<Slot>(); // List containing all possible timeslots
- private String name;
- private int points;
- // Constructor
- public Course(String name, int points, List<Slot> slots) {
- this.name = name;
- this.points = points;
- this.slots = slots;
- }
- public String getName() {
- return name;
- }
- }
- public class Student {
- private String name;
- private List<Course> courses = new ArrayList<Course>(); // List storing courses attended by this student
- List<Slot> freeslots = new ArrayList<Slot>(); // List storing slots still available (unscheduled) for student (unused in segment)
- private int studentnr; // Student identifier
- // Constructor
- public Student(String name, List<Course> courses, List<Slot> slots, int studentnr) {
- this.name = name;
- this.freeslots = slots;
- this.courses = courses;
- this.studentnr = studentnr;
- }
- // courses getter
- public List<Course> getCourses() {
- return courses;
- }
- // name getter
- public String getName() {
- return name;
- }
- }
- /*
- * Output given:
- *
- * The following courses have been found for student Nicolaos Haakonsson:
- * biology I, chemistry I
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement