RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1553 | Replies: 0
Reply
Join Date: Apr 2006
Posts: 9
Reputation: sidereal is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sidereal sidereal is offline Offline
Newbie Poster

Help cpu scheduling I don't know why is not working

  #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.......
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 2:32 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC