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

help programming in Java, in NetBeans IDE You have been asked to test the effect

ID: 3834524 • Letter: H

Question

help programming in Java, in NetBeans IDE

You have been asked to test the effectiveness of the following different scheduling algorithms for different types of queuing applications. 1) First-In-First-Out (FIFO): The jobs are processed in the arriving order. The job at the front of the queue is served until it has completed. That job is then removed from the queue. The next job at the front of the queue is served until it has completed and then it is removed from the queue. This process is continued until the queue is empty. 2) Shortest-Job-First (SJF): The job with the shortest processing time is processed first until it has completed. That job is then removed from the queue. The next job with smallest processing is then served until it has completed and then it is removed from the queue. This process is continued until the queue is empty. 3) Round-Robin (RR): Jobs are processed using a fixed time-slice. The jobs are initially kept in a queue based on the order of arrival. The job at the front of the queue is removed and served similar to the FIFO algorithm. However, unlike the FIFO algorithm, each job is served up to the pre-defined slice of time. If job can be completed within the allotted time it is fully served and removed from the queue. If the job cannot be completed in the allotted time, it is served for the allotted time and then added to the end of the queue to be served later for the remaining time. This process is continued until the queue is empty. The total turnaround time is the total time a job spends in the system: Turnaround time = processing time + waiting time (time spend in queue). For example, it the work load is 15 units, but it spends 50 units of time in queue, waiting to be processed, then the turnaround time is equal to 65 units. A) Write a program to test the effectiveness of these algorithms. Create 100 jobs, each with a random processing time of 0 to 100 time units. Then process the jobs according to the above scheduling methods. You can use an ArrayList for the FIFO and RR scheduling schemes. Implement the SJF using a binary heap (priority heap). Use a time slice of 20 units. Compare the average turnaround time for the different strategies. B) Experiment with different time slices for the RR strategy and compare the results. Use time slices in increments of 5 units and see if there are any differences in the average turnaround time.

Explanation / Answer

Q1: import java.io.*;

class FIFO
{
public static void main(String args[]) throws IOException
{
int fifo[]=new int[3];
int n;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println(“Enter the number of inputs :”);
n=Integer.parseInt(br.readLine());
int inp[]=new int[n];
System.out.println(“Enter the inputs:”);
for(int i=0;i<n;i++)
inp[i]=Integer.parseInt(br.readLine());
System.out.println(“.................");
for(int i=0;i<3;i++)
fifo[i]=-1;
int Hit=0;
int Fault=0;
int j=0;
boolean check;
for(int i=0;i<n;i++)
{
check=false;

for(int k=0;k<3;k++)
if(fifo[k]==inp[i])
{
check=true;
Hit=Hit+1;
}
if(check==false)
{
fifo[j]=inp[i];
j++;
if(j>=3)
j=0;
Fault=Fault+1;
} }

System.out.println(“HIT:”+Hit+” FAULT;”+Fault);
}
}

Q2: import java.util.Scanner;

class sjf {
public static void main(String args[])
{
int process[] = new int[10];
int ptime[] = new int[10];
int wtime[] = new int[10];
int temp, n, total=0;
float avg=0;
Scanner get = new Scanner(System.in);

System.out.println("Enter Number of Processes:");
n = get.nextInt();
for(int i=0;i<n;i++)
{
System.out.println("Enter Process "+(i+1)+" ID: ");
process[i] = get.nextInt();
System.out.println("Enter Process "+(i+1)+" Burst Time: ");
ptime[i] = get.nextInt();
}

for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)

{

if(ptime[i]>ptime[j])
{
temp = ptime[i];
ptime[i] = ptime[j];
ptime[j] = temp;
temp = process[i];
process[i] = process[j];
process[j] = temp;
}
}
}

wtime[0] = 0;
for(int i=1;i<n;i++)
{
wtime[i] = wtime[i-1]+ptime[i-1];
total = total + wtime[i];
}
avg = (float)total/n;
System.out.println("P_ID P_TIME W_TIME");
for(int i=0;i<n;i++)
{
System.out.println(process[i]+" "+ptime[i]+" "+wtime[i]);
}
System.out.println("Total Waiting Time: "+total);
System.out.println("Average Waiting Time: "+avg);
}
}

Q3: