PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/src/cmsc433/p2/Simulation.java

https://bitbucket.org/cmsc433_spring2012/project2
Java | 83 lines | 30 code | 9 blank | 44 comment | 2 complexity | 45329add011207f08174e6243f96f86f MD5 | raw file
  1. package cmsc433.p2;
  2. import java.util.List;
  3. /**
  4. * Simulation is the main class used to run the simulation. You may add any
  5. * fields (static or instance) or any methods you wish.
  6. */
  7. public class Simulation
  8. {
  9. // we suggest you implement this for use by other classes in
  10. // the simulation to log events
  11. public static void logEvent(SimulationEvent event)
  12. {
  13. }
  14. /**
  15. * Function responsible for performing the simulation. Returns a List of
  16. * SimulationEvent objects, constructed any way you see fit. This List will
  17. * be validated by a call to Validate.validateSimulation. This method is
  18. * called from Simulation.main(). We should be able to test your code by
  19. * only calling runSimulation.
  20. *
  21. * @param numEaters
  22. * the number of eaters wanting to enter the restaurant
  23. * @param numCooks
  24. * the number of cooks in the simulation
  25. * @param numTables
  26. * the number of tables in the restaurant (i.e. restaurant
  27. * capacity)
  28. * @param machineCapacity
  29. * the capicity of all machines in the restaurant
  30. */
  31. public static List<SimulationEvent> runSimulation(int numEaters,
  32. int numCooks, int numTables, int machineCapacity)
  33. {
  34. // TODO: Add all simulation code here, returning a List of
  35. // SimulationEvent objects
  36. // You may construct the list in any way you see fit. We recommend using
  37. // the Simulation.logEvent function.
  38. return null;
  39. }
  40. /**
  41. * Entry point for the simulation. All simulation code, however, should be
  42. * in runSimulation, so that we can test your simulation by only calling
  43. * runSimulation() then Validate.validateSimulation. This means that most
  44. * code from your original Simulation.main should probably now be in
  45. * Simulation.runSimulation.
  46. *
  47. * @param args
  48. * the command-line arguments for the simulation. There should be
  49. * exactly four arguments: the first is the number of eaters, the
  50. * second is the number of cooks, the third is the number of
  51. * tables in the restaurant, and the fourth is the number of
  52. * items each cooking machine can make at the same time.
  53. */
  54. public static void main(String args[]) throws InterruptedException
  55. {
  56. // Parameters to the simulation
  57. if (args.length != 4)
  58. {
  59. System.err
  60. .println("usage: java Simulation <#eaters> <#cooks> <#tables> <capacity>");
  61. System.exit(1);
  62. }
  63. int numEaters = new Integer(args[0]).intValue();
  64. int numCooks = new Integer(args[1]).intValue();
  65. int numTables = new Integer(args[2]).intValue();
  66. int machineCapacity = new Integer(args[3]).intValue();
  67. List<SimulationEvent> simEvents;
  68. // Run the simulation
  69. simEvents = runSimulation(numEaters, numCooks, numTables,
  70. machineCapacity);
  71. // Validate the simulation
  72. Validate.validateSimulation(simEvents);
  73. }
  74. }