Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

mplement three different scheduling algorithms. . FIFO - tasks are executed to c

ID: 3620199 • Letter: M

Question

mplement three different scheduling algorithms.

. FIFO - tasks are executed to completion in the order they are added.
.Shortest - the shortest task is executed to completion, then the next shortest task, etc.
.Round Robin - each task is executed for one unit of time in a rotation.

Tasks should be objects. A task is created with a duration that determines how long it should
execute. Tasks also have names and know how long they have executed.

Each scheduler should be an object derived from an abstract scheduler class. A scheduler will
accept and run a list of tasks. Running a task simply adds to the amount of time
the task has been executing. New tasks cannot be added once a scheduler begins running the tasks.

A separate class called "TestScheduler" should be created. It should be able to read in the
name and duration of each task from a file called "tasks.txt". It should create an object for
each scheduler, and an object for each task, and run the set of tasks with each scheduler.

Explanation / Answer

Dear.. // java code for FIFO algorithm: public final class TestScheduler { RingList list = new RingList(); public TestScheduler ( ) // Constructor { } public int size() // actual size { return list.size(); } public boolean contains( Object o ) { RingElement rh = list.getHead(); RingElement re = rh; while (re != null) { if (re.getObject().equals( o )) return true; re = re.getNext(); if (re == rh) re = null; } return false; } public void clear() { list.removeAllElements(); } public boolean remove( Object o ) { RingElement rh = list.getHead(); RingElement re = rh; while (re != null) { if (re.getObject().equals( o )) { list.remove( re ); return true; } re = re.getNext(); if (re == rh) re = null; } return false; } public void put( Object o ) // Add a object to the queue. { list.insert( new RingElement( o ), list.HEAD ); } public Object get( ) // Removes the oldest object from the queue { RingElement re = list.getTail(); list.remove( re ); return re.getObject(); } public Object peek( ) { return list.getTail().getObject(); } protected void finalize() throws Throwable { list.removeAllElements(); list = null; super.finalize(); } } ______________________________________________________________________ public class RoundRobin { private int len; private StubData[] sd; private double[] load; private Set previousSet = null; private static final double MIN_THRESHOLD_RESET = 100.0; public RoundRobin() { len = 0; } public RoundRobin(Set c) { reset(c); } private void reset(Set stubs) { previousSet = stubs; len = stubs.size(); sd = new StubData[len]; load = new double[len]; Iterator it = stubs.iterator(); for (int i = 0; i 0) { for (int i = 0; i