| | |
Pls Kindly help me
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2006
Posts: 8
Reputation:
Solved Threads: 0
I have a homework assignment that l started, but l ran into problems. Could you please look at my code and help me. The topic is as follow:
In this exercise, you will study the effect of several parameters used with RR scheduling. To solve the exercise, you will need to implement a discrete simulation to experiment with the performance of this strategy under different time slice lengths and different dispatcher overhead times. Do this by writing a simulation program to imitate the behavior of a single-CPU system that has a preemptive RR scheduler, and then collecting performance data regarding the operation of the simulation.
The Code is:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.Math;
public class Simulation
{
public static void main(String [] args) throws IOException
{
BufferedReader console = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("\n The time quantum (for Round
Robin algorithm)\n");
System.out.print("Time Quantum: ");
String input = console.readLine();
int quantum = Integer.parseInt(input);
int [] timequantum = new int[quantum];
for (int i=0;i<quantum;i++)
{
try
{
timequantum[i] = Integer.parseInt(in.readLine());
}
catch(NumberFormatException e)
{
System.out.println("You must enter a number!");
return;
}
}
//System.out.print("\n Dispatcher overhead times:\n");
//System.out.print("Dispatcher time");
//String input
//System.out.print("\n Arrival Time:");
//String input = console.readLine();
//int num = Integer.parseInt(input);
//int [] arrival = new int[num];
//for (int i=0;i<num;i++)
//{
// arrival[i]=console.readInt();
//}
///////////////////////////////////////////////////////////////////////////////////////////////
//System.out.print("\n Round Robin\n");
//float avgWait = getWaitRR(arrival, bursts, bursts2, quantum, num);
//System.out.println("\nAverage process waiting time:"+ avgWait);
//System.out.println();
}
static float getWaitRR(int [] p,int [] b, int [] b2,int q, int n)
{
float totalTurnAround = 0; //will hold the total TurnAround time
int[] turnAround=new int [n];
int avg=0,
totalBursts = 0;
for(int k=0;k<(b[n-1]);k++)
{
for(int i=0;i<n;i++)
{
if(b2[i]<q) //if the burst time for a process is less than the quantum
{
if(b2[i]!=0) //and if it is not equal to zero
{
for(int j=b2[i];j>0;j--)
{
avg++; //counts up all burst times
turnAround[i] = avg; //stores it in the correct array index
}
b2[i]=0; //makes sure there are no minus values
}
}
Else
{
for(int j=q;j>0;j--)
{
avg++; //counts up all burst times
if(b2[i]!=0) //if process bursts are != 0 then they haven't finished
turnAround[i] = avg; //over-right old time
}
b2[i]=b2[i]-q; //takes time quantum away from burst times, if it goes
below 0 it gets reset to 0
}
}
}
for(int i=0;i<n;i++)
totalTurnAround += turnAround[i]; //this gets the total turnaround time
totalTurnAround -= avg; //avg is the total burst time
return(totalTurnAround/n); //returns the average wait time
}
}
In this exercise, you will study the effect of several parameters used with RR scheduling. To solve the exercise, you will need to implement a discrete simulation to experiment with the performance of this strategy under different time slice lengths and different dispatcher overhead times. Do this by writing a simulation program to imitate the behavior of a single-CPU system that has a preemptive RR scheduler, and then collecting performance data regarding the operation of the simulation.
The Code is:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.lang.Math;
public class Simulation
{
public static void main(String [] args) throws IOException
{
BufferedReader console = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("\n The time quantum (for Round
Robin algorithm)\n");
System.out.print("Time Quantum: ");
String input = console.readLine();
int quantum = Integer.parseInt(input);
int [] timequantum = new int[quantum];
for (int i=0;i<quantum;i++)
{
try
{
timequantum[i] = Integer.parseInt(in.readLine());
}
catch(NumberFormatException e)
{
System.out.println("You must enter a number!");
return;
}
}
//System.out.print("\n Dispatcher overhead times:\n");
//System.out.print("Dispatcher time");
//String input
//System.out.print("\n Arrival Time:");
//String input = console.readLine();
//int num = Integer.parseInt(input);
//int [] arrival = new int[num];
//for (int i=0;i<num;i++)
//{
// arrival[i]=console.readInt();
//}
///////////////////////////////////////////////////////////////////////////////////////////////
//System.out.print("\n Round Robin\n");
//float avgWait = getWaitRR(arrival, bursts, bursts2, quantum, num);
//System.out.println("\nAverage process waiting time:"+ avgWait);
//System.out.println();
}
static float getWaitRR(int [] p,int [] b, int [] b2,int q, int n)
{
float totalTurnAround = 0; //will hold the total TurnAround time
int[] turnAround=new int [n];
int avg=0,
totalBursts = 0;
for(int k=0;k<(b[n-1]);k++)
{
for(int i=0;i<n;i++)
{
if(b2[i]<q) //if the burst time for a process is less than the quantum
{
if(b2[i]!=0) //and if it is not equal to zero
{
for(int j=b2[i];j>0;j--)
{
avg++; //counts up all burst times
turnAround[i] = avg; //stores it in the correct array index
}
b2[i]=0; //makes sure there are no minus values
}
}
Else
{
for(int j=q;j>0;j--)
{
avg++; //counts up all burst times
if(b2[i]!=0) //if process bursts are != 0 then they haven't finished
turnAround[i] = avg; //over-right old time
}
b2[i]=b2[i]-q; //takes time quantum away from burst times, if it goes
below 0 it gets reset to 0
}
}
}
for(int i=0;i<n;i++)
totalTurnAround += turnAround[i]; //this gets the total turnaround time
totalTurnAround -= avg; //avg is the total burst time
return(totalTurnAround/n); //returns the average wait time
}
}
•
•
Join Date: Mar 2006
Posts: 8
Reputation:
Solved Threads: 0
Thanks for replying.
My problem is that, have read the time quantum and the latency in while at the same time read in the start time and the burst times from a text file and then get the four of these figures to give me the average time waiting and the turnaround time. I m just totally lost on how to do this like i know how to calculate the times but after that im lost .
My problem is that, have read the time quantum and the latency in while at the same time read in the start time and the burst times from a text file and then get the four of these figures to give me the average time waiting and the turnaround time. I m just totally lost on how to do this like i know how to calculate the times but after that im lost .
![]() |
Similar Threads
- Internet Explorer & Windows Explorer (desktop shortcuts) Won't Load! (Viruses, Spyware and other Nasties)
- software project management plan (Computer Science)
- IE doesn't launch (Viruses, Spyware and other Nasties)
- writting screen saver program using J2ME (Java)
- DEfault web page has been jacked by a passthrough (Viruses, Spyware and other Nasties)
Other Threads in the Java Forum
- Previous Thread: Help!!!plz....
- Next Thread: Homework Help
| Thread Tools | Search this Thread |
actuate android api applet application applications array arrays automation balls bank binary bluetooth business c++ chat class classes clear client code codesnippet collections component coordinates database defaultmethod development dice doctype dragging ebook eclipse error formatingtextintooltipjava fractal froglogic game givemetehcodez graphics gui hql html ide image infinite ingres input integer intersect invokingapacheantprogrammatically j2me java javaprojects jni jpanel julia linux list loop looping map method methods mobile mysql netbeans newbie openjavafx parameter php print problem program programming project recursion repositories scanner screen scrollbar server set size sms sort sorting sql sqlserver state storm string sun superclass swing swt text-file threads tree windows





