[SOLVED] CSCI340 Assignment2

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment2-qze1ek.zip (194.3 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
5/5 - (2 votes)

Build a program which schedules simulated processes.

 

Design:

 

  1. The simulator implements three different CPU scheduling algorithms. The simulator selects a process to run from the ready queue based on the scheduling algorithm chosen at runtime.  Since the assignment intends to simulate a CPU scheduler, it does not require any actual process creation or execution.  When the CPU scheduler chooses the next process, the simulator will simply print out which the process selected to run at that time.  The simulator output is like a Gantt chart.

 

  1. A Process is an object in this assignment storing integers which are its ID, arrival time, and CPU burst length. Another object in this assignment is the Scheduler which simulates the CPU scheduler for an operating system, the one chosen at runtime.  The scheduler contains the ready queue and the only operations the scheduler performs is add and remove.  The add operation adds a process into the ready queue into its appropriate spot within the ready queue according to the CPU scheduling algorithm, the one chosen at runtime.  The remove operation removes a process from the ready queue according to the CPU scheduling algorithm, the one chosen at runtime.  The scheduler implements the CPU scheduling algorithms: First Come First Serve, Shortest Remaining Time First which is the preemptive version of Shortest Job First, and Round Robin.

 

  1. Create a driver class and make the name of the driver class Assignment2 and it should only contain only one method: public static void main(String args[]).

The main method receives, via the command line arguments, the name of the CPU scheduler that your simulator program will use.  If Round Robin is the CPU scheduler chosen, then the main method also receives the time quantum value via an additional command line argument.  The main method opens the file assignment2.txt reading in the entire set of processes and initiates execution of the simulator program.  Assume there is only a single processor with only one core.  The main method itself should be fairly short.

 

The command to launch the program using First Come First Serve scheduling: java Assignment2 FCFS

 

The command to launch the program using Shortest Remaining Time First scheduling: java Assignment2 SRTF

 

The command to launch the program using Round Robin scheduling with a time quantum of 10: java Assignment2 RR 10

 

 

  1. The input to the program reads from a plain text file called txt. This is the statement to use to open the file:

 

FileInputStream fstream = new FileInputStream(“assignment2.txt”);

 

Assuming you are using Eclipse to create your project, you will store the input file assignment2.txt in the parent directory of your source code (.java files) which happens to be the main directory of your project in Eclipse.  If you are using some other development environment, then you have to figure out where to store the input file.

 

Each line in the file represents a process, 3 integers separated by a space or spaces.  The process information includes the process ID, arrival time, and CPU burst length.  Arrival time is the time at which the scheduler receives the process and places it in the ready queue.  You can assume arrival times of the processes in the input file are in non-decreasing order.  Process IDs are unique.  Arrival times may be duplicated, which means multiple processes may arrive at the same time.  The following table is an example of a three process input file.  The text in the top row of the table is just to label the value in each column and would not appear in the input file.  Remember, a space or spaces separate the integers on each line.

 

Process ID Arrival Time CPU Burst Length
1 0 10
2 0 20
3 3 5

 

  1. For the output, the example below best describes what the program should produce. The program will not be tested on this sample input but a different sample input.

 

Here is the example input:

 

  • 0 10
  • 0 9
  • 3 5
  • 7 4
  • 10 6
  • 10 7

 

Here is the output produced for the above example input given the command java Assignment2 FCFS to execute the program:

 

Scheduling algorithm: First Come First Serve

============================================================

<system time    0> process    1 is running

<system time    1> process    1 is running

<system time    2> process    1 is running

<system time    3> process    1 is running

<system time    4> process    1 is running

<system time    5> process    1 is running

<system time    6> process    1 is running

<system time    7> process    1 is running

<system time    8> process    1 is running

<system time    9> process    1 is running <system time   10> process    1 is finished….

<system time   10> process    2 is running

<system time   11> process    2 is running

<system time   12> process    2 is running

<system time   13> process    2 is running

<system time   14> process    2 is running

<system time   15> process    2 is running

<system time   16> process    2 is running

<system time   17> process    2 is running

<system time   18> process    2 is running <system time   19> process    2 is finished….

<system time   19> process    3 is running

<system time   20> process    3 is running

<system time   21> process    3 is running

<system time   22> process    3 is running

<system time   23> process    3 is running <system time   24> process    3 is finished….

<system time   24> process    4 is running

<system time   25> process    4 is running

<system time   26> process    4 is running

<system time   27> process    4 is running <system time   28> process    4 is finished….

<system time   28> process    5 is running

<system time   29> process    5 is running

<system time   30> process    5 is running

<system time   31> process    5 is running

<system time   32> process    5 is running

<system time   33> process    5 is running <system time   34> process    5 is finished….

<system time   34> process    6 is running

<system time   35> process    6 is running

<system time   36> process    6 is running

<system time   37> process    6 is running

<system time   38> process    6 is running

<system time   39> process    6 is running

<system time   40> process    6 is running

<system time   41> process    6 is finished….

<system time   41> All processes finished……

============================================================

Average CPU usage:       100.00%

Average waiting time:     14.17

Average response time:    14.17

Average turnaround time:  21.00

============================================================

 

 

  1. You must declare public each class you create which means you define each class in its own file.

 

  1. You must declare private all the data members in every class you create.

 

  1. It is possible to use inheritance in this assignment, extends one class in another class. But, it has to be the proper use of inheritance.  If you simply use extends in one class to allow it access to the private data members of another class and the two classes do not have similar behavior, then that is not the proper use of inheritance.  Improper use of inheritance will cause a loss in points.

 

  1. Tip: Make your program as modular as possible, not placing all your code in one .java file. You can create as many classes as you need in addition to the class described above.  Methods being reasonably small follow the guidance that “A function does one thing and does it well.”  You will lose a lot of points for code readability if you do not make your program as modular as possible.  But do not go overboard on creating classes and methods.  Your common sense guides your creation of classes and methods.

 

  1. Do NOT use your own packages in your program. If you see the keyword package on the top line of any of your .java files, then you created a package.  Create every .java file in the src folder of your Eclipse project, if you’re using Eclipse.

 

  1. Do NOT use any graphical user interface code in your program!

 

  1. Do NOT type any comments in your program. If you do a good job of programming by following the advice in number 9 above, then it will be easy for me to determine the task of your code.

 

  • Assignment2-qze1ek.zip