cpu scheduling I don't know why is not working

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2006
Posts: 9
Reputation: sidereal is an unknown quantity at this point 
Solved Threads: 0
sidereal sidereal is offline Offline
Newbie Poster

cpu scheduling I don't know why is not working

 
0
  #1
Apr 15th, 2006
Please people help me with some ideas...
everything is necessary now.....

here is my code:
this thing is supposed to read from a file random numbers
and generate the so called Process control block with burst time and the number of the process:


import java.util.Scanner;
import java.io.*;

public class PassProcess {
private int psgrId;
private int burstTime;
private static int idNum = 0;

public PassProcess()
{
burstTime = 0;
psgrId = 0;
}
public PassProcess(int burstTime) {
this.burstTime = burstTime;
this.psgrId = idNum++;
}
public int getBurstTime () {
try{


Scanner sc = new Scanner(
new FileReader("burst_time.txt"));
while(sc.hasNextInt()) {
burstTime = sc.nextInt();
}
}
catch(IOException e) {
System.out.println("Error reading from file.");
}
return burstTime;
}

public int getId ()
{ return psgrId; }

}


this other thing is supposed to generate 200 processes and output them into a queue... somehow I cannot figure out how to create the queue and then use methods to get the burst time and priority and at the same time to run the right algorithm with the right output


import java.util.*;
import java.io.*;
import java.util.Scanner;
import java.util.ArrayList;
import ds.util.LinkedQueue;


public class NewPCBRunner
{
private double average_W;
private double Twt,Awt;
private int highest;
private PassProcess[] record;
double[] Wt = new double[200];
LinkedQueue q = new LinkedQueue();

public void getFigures()
{
PassProcess[] record = new PassProcess[200];
int i;
for(i=0; i<record.length; i++)
{
record[i]= new PassProcess();

}
}
public void FCFS()
{
Twt = 0.0;
double nextBurstTime = record[0].getBurstTime();

Wt[1]=0;
for(int i=2; i<200; i++)
{
nextBurstTime = record[i].getBurstTime();
Wt[i]= nextBurstTime + Wt[i-1];
}
for(int i =2; i<200; i++){
Twt = Twt + Wt[i];
Awt = Twt/200;
}
}
public void displayResults()
{
System.out.println("Total waiting time for FCFS is " + Twt);
System.out.println("Average waiting time " + Awt);
System.out.println("These are the processes with highest priority " + highest);
System.out.println();
}


public static void main(String[] args)
{
NewPCBRunner process = new NewPCBRunner();
process.getFigures();
process.FCFS();
process.displayResults();
}
}

P.S. is always gives me the same mistake whatever i try

Exception in thread "main" java.lang.NullPointerException
at NewPCBRunner.FCFS(NewPCBRunner.java:31)
at NewPCBRunner.main(NewPCBRunner.java:60)
Java Result: 1

I don't know what it meanss.......
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC