mmayoub

Airport system, Utils class

Aug 25th, 2017
94
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package AirportPkg;
  2.  
  3. import java.util.Date;
  4. import java.util.Random;
  5.  
  6. import AirportPkg.Airplane.AirplaneState;
  7.  
  8. public class Utils {
  9.     private static Random rnd = new Random();
  10.  
  11.     // time between two airplanes calls
  12.     private static int minCallTime = 50;
  13.     private static int maxCallTime = 150;
  14.  
  15.     // time for airplane to land
  16.     private static int minLandTime = 30;
  17.     private static int maxLandTime = 230;
  18.  
  19.     // time for airplane to take off
  20.     private static int minTakeOffTime = 80;
  21.     private static int maxTakeOffTime = 260;
  22.  
  23.     // array of final states for an airplane, defined in Airplane.java
  24.     private static AirplaneState[] stateArray = AirplaneState.values();
  25.  
  26.     // print a log message
  27.     public static void printLog(String tag, String message) {
  28.         System.out.printf("%d : %-6s : %s\n", (new Date()).getTime(), tag,
  29.                 message);
  30.     }
  31.  
  32.     // get random time to the next airplane call
  33.     public static int getNextCallTime() {
  34.         return minCallTime + rnd.nextInt(maxCallTime - minCallTime + 1);
  35.     }
  36.  
  37.     // get random time for airplane to land
  38.     public static int getLandingTime() {
  39.         return minLandTime + rnd.nextInt(maxLandTime - minLandTime + 1);
  40.     }
  41.  
  42.     // get random time for airplane to take off
  43.     public static int getTakingOffTime() {
  44.         return minTakeOffTime
  45.                 + rnd.nextInt(maxTakeOffTime - minTakeOffTime + 1);
  46.     }
  47.  
  48.     // get random state for an airplane
  49.     public static AirplaneState getRandomState() {
  50.         return stateArray[rnd.nextInt(stateArray.length)];
  51.     }
  52.  
  53. }
RAW Paste Data