The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 3 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Hey, I need help.It is a java question. If you have any question please let me know. The answer should write by yourself and follow every instructions. Thanks so much.import java.util.Random;
/**
 * Simulates an operating system for the purposes of testing a scheduler. It creates
 * a bunch of jobs and then runs them until they are done outputing the information
 * on which job is scheduled and when.
 *
 *
 */
public class Simulation
{
       private Queue scheduler;
      Â
       private static final int DEFAULT_TIME = 100;
       private static final int NUMBER_OF_JOBS = 10;
       private static final int PRIORITY_LEVELS = 3;
       private static final int MAX_DURATION = 1000;
      Â
       /**
        * Creates an Operating System Simulator to test a given scheduler.
        *
        * @param scheduler The scheduler to test. The scheduler should use the Queue
        * interface.
        */
       public Simulation(Queue scheduler)
       {
               this.scheduler = scheduler;
       }
      Â
       /**
        * Runs the simulator by creating a certain number of Jobs and then running
        * until all the Jobs are completed. It outputs a progress report at each time
        * it retrieves a new Job from the scheduler and runs it. By default it runs
        * each Job for 100 milliseconds at a time, however, if a Job finishes before
        * that time has elapsed the remaining time is given to the next Job.
        */
       public void run()
       {
               if (scheduler == null)
               {
                       return;
               }
              Â
               Random generator = new Random();
               System.out.println("Creating jobs...");
               for (int i = 0; i < NUMBER_OF_JOBS; i ++)
               {
                       Job temp = new Job(generator.nextInt(PRIORITY_LEVELS),
                                          generator.nextInt(MAX_DURATION));
                       scheduler.enqueue(temp);
                       System.out.println(temp);
               }
              Â
               System.out.println();
               System.out.println("Running jobs...");
               int time = DEFAULT_TIME;
               while (!scheduler.isEmpty())
               {
                       Job active = scheduler.dequeue();                      Â
                      Â
                       System.out.println("Running Job " + active.getId() + " for " + time + " milliseconds..");
                       if (active.getDuration() >= time)
                       {
                               active.run(time);
                               time = DEFAULT_TIME;
                       }
                       else
                       {
                               time = DEFAULT_TIME + time - active.getDuration();
                               active.run(active.getDuration());
                       }                      Â
                       System.out.print("..." + active); Â
                      Â
                       if (active.getDuration() > 0)
                       {public interface Queue
{
       // TODO Fill in interface
}
                               scheduler.enqueue(active);
                               System.out.println();
                       }
                       else
                       {
                               System.out.println(" COMPLETE!");
                       }
               }
       }
      Â
       /**
        * The main method creates the scheduler and the operating system simulator
        * on which to test it. It also runs the simulator. Modify the main method
        * in order to change the scheduler and compare the results.
        */
       public static void main(String[] args)
       {
               Queue jobs = null; // Replace null with the queue you want to test
               Simulation simulator = new Simulation(jobs);
               simulator.run();
       }
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly