| | |
cpu scheduling I don't know why is not working
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 9
Reputation:
Solved Threads: 0
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.......
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
- cpu scheduling algorithm please (Community Introductions)
- What is the best programming language to do scheduling program? (Computer Science)
- Simulation for CPU Scheduling (C++)
- cpu scheduling program (Java)
- CPU scheduling algorithms (RR, SJF, and Priority). (Java)
- CPU Scheduling Algorithm (Java)
- Cpu scheduling algorithm (C)
Other Threads in the Java Forum
- Previous Thread: CPU Scheduling Algorithm
- Next Thread: Testing applets and reloading...
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary bluetooth character chat class classes client code component consumer csv database desktop draw eclipse error event exception fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie objects online oracle oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion robot rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time tree ubuntu windows working






