University stuff.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import java.util.ArrayList;
  2. import java.util.Arrays;
  3. import java.io.File;
  4. class Main {
  5. public static void main(String[] args) {
  6. if (args.length != 2) {
  7. System.out.println("Expected 2 arguments");
  8. System.exit(1);
  9. }
  10. String filename = args[0];
  11. int manpower = Integer.parseInt(args[1]);
  12. Project p = new Project();
  13. try {
  14. p.readFile(new File(filename));
  15. } catch (Exception ex) {
  16. System.out.println("Failed to read file "+filename);
  17. return;
  18. }
  19. if (findCycle(p))
  20. return;
  21. p.calcTimes();
  22. System.out.println("\nTasks:");
  23. p.printTasks();
  24. System.out.println("\nTimes:");
  25. p.printTimes(manpower);
  26. }
  27. static void printTaskList(ArrayList<Task> l) {
  28. boolean first = true;
  29. for (int i = l.size() - 1; i >= 0; --i) {
  30. Task t = l.get(i);
  31. // Print arrows for everything but the first task
  32. if (!first) {
  33. System.out.print(" -> ");
  34. } else {
  35. first = false;
  36. }
  37. System.out.print(t.name);
  38. }
  39. System.out.println("");
  40. }
  41. static boolean findCycle(Project p) {
  42. ArrayList<Task> l = p.findCycle();
  43. // We found a cycle
  44. if (l != null) {
  45. System.out.println("The project is not realizable.");
  46. printTaskList(l);
  47. return true;
  48. // We found no cycle
  49. } else {
  50. System.out.println("The project is realizable.");
  51. return false;
  52. }
  53. }
  54. }