This program creates an array of assignments and sorts them in order from the earliest end first to the latest end time last. Also there is a Boolean array to keep track of which assignments can actually be used(true if actually on the schedule). Once they are sorted, I am supposed to create a schedule method that will take the assignments and turn each assignments' corresponding Boolean to true if it can be placed on the schedule. The first assignment on the list of 12 assignments is the current assignment and its corresponding Boolean must be set to true, then every assignment after the current assignment whose start time is before the end time of the current assignment must be skipped, then once you reach the first assignment whose start time is after the end time of the current assignment that assignment's corresponding Boolean must be set to true, then the same process again, etc... I have a for loop in the Schedule method, because I'm pretty sure that's what I need but I can't figure out how to set it up. Thanks.
Here is the code:
package homework4; import java.io.*; import java.util.Scanner; public class Scheduler { Assignment[] assign = new Assignment[12]; boolean[] b = new boolean[12]; public void load(Scanner sc) { int numberOfAssign = sc.nextInt(); for (int i = 0; i < assign.length; i++) { assign[i] = new Assignment(sc.next(), sc.nextInt(), sc.nextInt()); // System.out.println(assign[i].getStartTime()); } } private void sort(Assignment[] array) { int i, j; int maxindex; for (i = array.length - 1; i >= 1; i--) { maxindex = 0; for (j = 1; j <= i; j++) { if (array[j].getEndTime() > array[maxindex].getEndTime()) { maxindex = j; } } // swap minindex and i Assignment temp = array[i]; array[i] = array[maxindex]; array[maxindex] = temp; } } public void Schedule() { sort(assign); for (int i = 0; i < assign.length; i++) { } }