add.(Recall.getResource());
import java.util.ArrayList;
import java.util.Random;
import java.util.*;
public class Process
{
//5 process states
final static int NEW = 0;
final static int READY = 1;
final static int RUNNING = 2;
final static int WAITING = 3;
final static int EXITING = 4;
//header info
int stackSize;
int programCounter;
int processSize;
int burstTime;
int remainingTime;
int numRequested;
int IOTime;
int waitTime = 0;
int TurnAround;
int pageTable [];
ArrayList<Resource> requestedDevices = new ArrayList<Resource>();
ArrayList<Resource> allocatedDevices = new ArrayList<Resource>();
Random rand = new Random();
final int maxSize=4096*(2^10), minSize=4096*1, maxDevices=5, minBurst=1, maxBurst=8; //change these to whatever is needed
//constructor creates a process with random values
public Process()
{
processSize = rand.nextInt(maxSize-minSize)+minSize; //random process size between min and max
pageTable = new int [(processSize/4096) + 1];
numRequested = rand.nextInt(maxDevices);
//for (int i=0;i<numRequested;i++){ //set some random devices to be requested
requestedDevices.add() .getResource("Resource.java");
//}
IOTime = requestedDevices.get(0).getTime();
burstTime = rand.nextInt(maxBurst-minBurst)+minBurst + requestedDevices.get(0).getTime(); //random burst time between min and max
remainingTime = burstTime;
}
//this method acts as the loader and creates a PCB for a process
public PCB loader(int pid, int entryTime)
{
return (new PCB(pid, entryTime));
}
}
the compiler returns an error saying:
./Process.java:41: cannot find symbol
symbol : method add()
location: class java.util.ArrayList<Resource>
requestedDevices.add() .getResource("Resource.java");
I believe I need to define the method add but don't how or if this will work???
Re: add.(Recall.getResource());
The add() method is contained within the ArrayList class, and expects to get a parameter of type Resource. For instance, let's say you created ArrayList of type String and you wanted to add a new element to it, it would look something like this:
Code java:
import java.util.ArrayList;
public class Test {
public static void main(String[] args)
{
ArrayList<String> strings = new ArrayList<String>(0);
strings.add("New string to add"); //This will add the new String element to the ArrayList
System.out.prinltn(string.get(0)); // Print the first element in the ArrayList
}
}
In other words you need to pass a Resource object as the parameter in the add(parameter goes here) method.