import java.util.ArrayList; import java.util.Arrays; import java.io.File; class Main { public static void main(String[] args) { if (args.length != 2) { System.out.println("Expected 2 arguments"); System.exit(1); } String filename = args[0]; int manpower = Integer.parseInt(args[1]); Project p = new Project(); try { p.readFile(new File(filename)); } catch (Exception ex) { System.out.println("Failed to read file "+filename); return; } if (findCycle(p)) return; p.calcTimes(); System.out.println("\nTasks:"); p.printTasks(); System.out.println("\nTimes:"); p.printTimes(manpower); } static void printTaskList(ArrayList l) { boolean first = true; for (int i = l.size() - 1; i >= 0; --i) { Task t = l.get(i); // Print arrows for everything but the first task if (!first) { System.out.print(" -> "); } else { first = false; } System.out.print(t.name); } System.out.println(""); } static boolean findCycle(Project p) { ArrayList l = p.findCycle(); // We found a cycle if (l != null) { System.out.println("The project is not realizable."); printTaskList(l); return true; // We found no cycle } else { System.out.println("The project is realizable."); return false; } } }