SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 305 Weeks Ago, 1 Day Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 16 Nov 2017 My Price 10.00

Simulates an operating system for the purposes

Please help me to solve this assignment related in queue in java.

  • 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)
                            {
                                    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();
            }
    }

Attachments:

Answers

(5)
Status NEW Posted 16 Nov 2017 12:11 PM My Price 10.00

-----------  ----------- 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

Not Rated(0)