scheduler-simulator

git clone git://git.codymlewis.com/scheduler-simulator.git
Log | Files | Refs | README

A1.java (1495B)


      1 /**
      2  * <h1>A1 - Comp2240</h1>
      3  *
      4  * The main interface class for the First Assignment of COMP2240 Operating
      5  * Systems. This simulates and compares a few scheduling algortihms.
      6  *
      7  *
      8  * @author Cody Lewis (c3283349)
      9  * @version 1
     10  * @since 2019-08-16
     11  */
     12 
     13 public class A1 {
     14     public static void main(String args[]) {
     15         if (args.length < 1) {
     16             System.out.println("A1: missing an input file");
     17             System.out.println("Usage: java A1 INPUT_FILE");
     18 
     19             System.exit(1);
     20         }
     21 
     22         String[] dispatcherNames = {"FCFS", "RR", "FB (constant)", "NRR"};
     23         Dispatcher[] dispatchers = new Dispatcher[dispatcherNames.length];
     24 
     25         for (int i = 0; i < dispatcherNames.length; ++i) {
     26             System.out.println(String.format("%s:", dispatcherNames[i]));
     27             dispatchers[i] = new Dispatcher(dispatcherNames[i], args[0]);
     28             System.out.println(dispatchers[i].run());
     29         }
     30 
     31         System.out.println("Summary");
     32         System.out.println("Algorithm\tAverage Turnaround Time\tAverage Waiting Time");
     33         for (int i = 0; i < dispatcherNames.length; ++i) {
     34             String algName;
     35             if (dispatcherNames[i].length() > 8) {
     36                 algName = String.format("%s\t", dispatcherNames[i]);
     37             } else {
     38                 algName = String.format("%s\t\t", dispatcherNames[i]);
     39             }
     40             System.out.format("%s%s\n", algName, dispatchers[i].summary());
     41         }
     42 
     43         System.exit(0);
     44     }
     45 
     46 }