This lab assignment is filled with a lot of information, i tried the best i coul
ID: 665906 • Letter: T
Question
This lab assignment is filled with a lot of information, i tried the best i could to shorten the lab info. Also please comments on code so i know what you are doing.
In this lab you will write a Java program that will simulate an operating system’s job scheduling policy to determine which process will be assigned the CPU when it becomes available. We will utilize a system of queues to simulate a sophisticated job scheduling mechanism, the multi-level feedback queue (MFQ).
Here are materials on what to use for this lab below.
- The input to this simulation will consist of job requests, each composed of three elements:
Arrival time – Time job is initially submitted to the pattern
Process identifier (pid) – Identifies each process as it travels through the system
CPU time – CPU time required by the process to complete its job
- The output, displayed in a tabular format, should include a table entry each time a job enters the system indicating the:
Event
System time
Processor identifier (pid)
CPU time needed
- When a process a completes and leaves the system, an appropriate table entry should be output to the indicate:
Event
System time
Process identifier (pid)
Total time in the system
Identify of the lowest- level queue in which the process resided
- When the simulation is complete, you should also output the following:
Total number of jobs
Total time of all jobs in system – sum of the time each job is in the system
Average response time – where response time is defines as the interval from the time a process enters the system to the time of first response, or the time it starts running
Average turnaround time for the jobs – where turnaround time is defined as the interval from the time a process enters the system to the time of its completion
Average waiting time – where waiting is the amount of time that a process is kept waiting in a queue
Average throughout for the system as a whole – the number of jobs divided by the sum of total time of all jobs in the system
Total CPU idle time – time the CPU has no jobs to run
- Be sure that your program sends all output to a file called csis.txt. This output file will be submitted along with our source code for the lab.
- Be sure all your data is properly labeled and all average values are displayed to two decimal places.
- Here is the data set, mfq.txt, which your program should run on:
2 101 3
7 102 1
9 103 7
12 104 5
14 105 1
17 106 1
18 107 50
24 108 2
34 109 12
37 110 3
44 111 10
45 112 48
50 113 1
56 114 1
71 115 3
81 116 2
- You should use at least the following classes in the lab:
Driver Job MFQ CPU ObjectQueue
- The Job class should include these class variables
pid
arrivalTime
cpuTimeRequired
cpuTimeRemaining
currentQueue
- The CPU class include these class variables:
job
cpuQuantumClock
busyFlag
So far i have two classes already made, i just need help with creating MFQ, JOB, and CPU Classes.
// Driver Class Java
Import java.io*;
public class Driver
{
publice static void(String [ ] args) throws IOException
{
PrintWriter pw = new PrintWriter(new FileWriter(“csis.txt”));
MFQ mfq = new MFQ(pw);
mfw.getJobs();
mfw.outputHeader();
mfw.runSimulation();
mfw.outStats();
pw.close();
}
}
This is what the output may look like
System Time Time In Event PID Needed System Queue Arrival 101 101 102 Departure 102 103 104 105 Departure 12 105 106 Departure 106 107 108 Departure 50 Departure Departure Departure 26 30 31 108 103 104 21 19 34 37 109 110 Departure 40 110 112 113 45 48 50 51 56 113 114 Departure 57 114 115 Departure 71 Departure Departure 74 79 115 109 45 81 116 116 Departure Departure Departure Departure 83 118 152 155 74 107 137 112 107 Total Number of jobs: 16 Total time of all jobs in system: 155 Average response time: 0 Average turnaround time for the jobs: 26.31 Average waiting time: 16.94 Average throughput: 0.10 Average cpu idle time:0Explanation / Answer
import java.io.*;
import java.util.Scanner;
interface ObjectQueueInterface
{
public boolean objisEmpty();
public boolean objisFull();
public void objclear();
public void objinsert(Object x);
public Object objremove();
public Object objquery();
}
class CPU
{
ObjectQueue Oq1 = new ObjectQueue();
ObjectQueue Oq2 = new ObjectQueue();
ObjectQueue Oq3 = new ObjectQueue();
ObjectQueue Oq4 = new ObjectQueue();
int a_cpuTime = 0, a_quantum = 0;
private PrintWriter writer;
Job cpujob = new Job(writer);
int jobID = cpujob.getProcessjobID();
int enQue = cpujob.enQue();
int a_workTime = 0;
public CPU(PrintWriter Objwri)throws IOException
{
this.writer = Objwri;
}
public void cpudoWork(Object queueTop12)
{
cpujob.cutter((String)queueTop12);
if(cpujob.enQue() == a_cpuTime)
{
Oq1.objinsert(queueTop12);
a_workTime = cpujob.a_workTime();
cpuqueueOne();
}
else if(Oq1.objisEmpty() && Oq2.objisEmpty() && Oq3.objisEmpty() && Oq4.objisEmpty())
{
a_cpuTime++;
cpudoWork(queueTop12);
}
else if(!Oq1.objisEmpty())
{
cpuqueueOne();
cpudoWork(queueTop12);
}
else if(!Oq2.objisEmpty())
{
cpuqueueTwo();
cpudoWork(queueTop12);
}
else if(!Oq3.objisEmpty())
{
cpuqueueThree();
cpudoWork(queueTop12);
}
else if(!Oq4.objisEmpty())
{
cpuqueueFour();
cpudoWork(queueTop12);
}
}
public int cpugetTime()
{
return a_cpuTime;
}
public void cpuqueueOne()
{
if(a_quantum < 2 && a_workTime > 0)
{
a_quantum++;
a_workTime--;
a_cpuTime++;
}
else if(a_workTime == 0)
{
System.out.println("Arrival " + Oq1.objremove());
a_workTime = cpujob.a_workTime();
a_quantum = 0;
}
else
{
Oq2.objinsert(Oq1.objremove());
System.out.println("1: " + a_cpuTime + " " + a_quantum);
a_quantum = 0;
cpuqueueTwo();
}
}
public void cpuqueueTwo()
{
if(a_quantum < 4 && a_workTime > 0)
{
a_quantum++;
a_workTime--;
a_cpuTime++;
}
else if(a_workTime == 0)
{
//System.out.println( a_cpuTime + " " + a_quantum);
System.out.println("Arrival " + Oq2.objremove());
a_workTime = cpujob.a_workTime();
a_quantum = 0;
}
else
{
Oq3.objinsert(Oq2.objremove());
System.out.println("Arrival "+ " " + a_quantum);
System.out.println("Departure"+ a_cpuTime + " " + a_quantum);
a_quantum = 0;
cpuqueueThree();
}
}
public void cpuqueueThree()
{
if(a_quantum < 8 && a_workTime > 0)
{
a_quantum++;
a_workTime--;
a_cpuTime++;
}
else if(a_workTime == 0)
{
//System.out.println("Departure" + a_cpuTime + " " + a_quantum+"3: ");
System.out.println("Arrival " + Oq3.objremove());
a_workTime = cpujob.a_workTime();
a_quantum = 0;
}
else
{
Oq4.objinsert(Oq3.objremove());
System.out.println( "Arrival "+ " " + a_quantum);
a_quantum = 0;
cpuqueueFour();
}
}
public void cpuqueueFour()
{
if(a_quantum < 16 && a_workTime > 0)
{
a_quantum++;
a_workTime--;
a_cpuTime++;
}
else if(a_workTime == 0)
{
System.out.println("Arrival " + Oq4.objremove()+ "4: ");
a_quantum = 0;
a_workTime = cpujob.a_workTime();
}
else
{
Oq4.objinsert(Oq4.objremove());
//System.out.println("Departure"+ a_cpuTime + " " + a_quantum);
System.out.println(a_workTime);
System.out.println(Oq4.objquery());
}
}
}
class Job
{
File newFile12=new File("mfq.txt");
Scanner a_read = new Scanner(newFile12);
String as = a_read.nextLine();
String[] st = as.split("\s+");
public Job(PrintWriter write)throws IOException
{
}
public Job(PrintWriter write, Scanner a_read) throws IOException
{
this.a_read = a_read;
}
public void jobformatS()
{
if(as.startsWith(" "))
as = as.replaceFirst(" ", "");
else;
}
public void job(Scanner a_read)throws IOException
{
as = a_read.nextLine();
jobformatS();
st = as.split("\s+");
}
public Object jjobList()
{
return enQue() + " " + getProcessjobID() + " " + a_workTime();
}
public void cutter(String newqueue)
{
st = newqueue.split("\s+");
}
public int enQue()
{
return Integer.parseInt(String.valueOf(st[0]));
}
public int getProcessjobID()
{
return Integer.parseInt(String.valueOf(st[1]));
}
public int a_workTime()
{
return Integer.parseInt(String.valueOf(st[2]));
}
}
//MFQ.java
class MFQ extends Driver
{
private PrintWriter writer;
ObjectQueue newque = new ObjectQueue();
CPU newcpu = new CPU(writer);
Scanner a_read = new Scanner(new File("mfq.txt"));
Job newjob = new Job(writer, a_read);
public MFQ(PrintWriter Objwri)throws IOException
{
this.writer = Objwri;}
public void cpugetJobs()throws IOException
{
Job newjob = new Job(writer, a_read);
if(!a_read.hasNextLine()){}
else
{
newjob.job(a_read);
newque.objinsert(newjob.jjobList());
cpugetJobs();
}
}
public void cpuoutputHeader()
{
System.out.println(" Event System Time PID Time Needed Time in System Level Queue");
}
public void runSimulation()throws IOException
{
if(!newque.objisEmpty())
{newcpu.cpudoWork(newque.objremove());
System.out.println("Departure "+newcpu.cpugetTime());
if(!newque.objisEmpty())
System.out.println(newque.objquery());
else;
runSimulation();}
}
public void outStats()
{
//FIND THE STATS OF QUEUE
if(!newque.objisEmpty())
{//System.out.println("Departure "+newque.objquery());
writer.println(newque.objremove());
outStats();
}
}
}
//ObjectQueue.java
class ObjectQueue implements ObjectQueueInterface
{
private Object[] item;
private int front;
private int rear;
private int size;
public ObjectQueue()
{
size = 100;
item = new Object[size];
front = size-1;
rear = size-1;
}
public ObjectQueue(int max)
{
size = max;
item = new Object[size];
front = size-1;
rear = size-1;
}
public boolean objisEmpty()
{
return front == rear;
}
public boolean objisFull()
{
return rear == size-1 ? front == 0 : front == rear+1;
}
public void objclear()
{
item = new Object[size];
front = size-1;
rear = size-1;
}
public void objinsert(Object x)
{
if (objisFull())
{
System.out.println("RUNTIME ERROR: QUEUE OVERFLOW");
System.exit(1);
}
if (rear == size-1)
rear = 0;
else
rear++;
item[rear] = x;
}
public Object objremove()
{
if (objisEmpty())
{
System.out.println("RUNTIME ERROR: QUEUE UNDERFLOW");
System.exit(1);
}
if (front == size-1)
front = 0;
else
front++;
Object temp = item[front];
item[front] = null;
return temp;
}
public Object objquery()
{
if (objisEmpty())
{
System.out.println("RUNTIME ERROR: QUEUE UNDERFLOW");
System.exit(1);
}
if (front == size-1)
return item[0];
else
return item[front+1];
}
}
public class Driver
{
public static void main(String[] args) throws IOException
{
PrintWriter newpw = new PrintWriter(
new FileWriter("csis.txt"));
MFQ mfq = new MFQ(newpw);
mfq.cpugetJobs();
mfq.cpuoutputHeader();
mfq.runSimulation();
mfq.outStats();
newpw.close();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.