944,137 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2747
  • Java RSS
Apr 15th, 2006
0

cpu scheduling I don't know why is not working

Expand Post »
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.......
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sidereal is offline Offline
9 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: CPU Scheduling Algorithm
Next Thread in Java Forum Timeline: Testing applets and reloading...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC