mirror of
https://github.com/zach-sb/COMP2240-Assignment1.git
synced 2024-07-02 12:04:00 +10:00
Coverted from array to linked list
This commit is contained in:
parent
ab4ee99b78
commit
0f36bb2440
@ -3,15 +3,14 @@ import java.io.*;
|
||||
|
||||
public class Scheduler {
|
||||
//Address of File name relative to code. Replace with request for filename?
|
||||
String fileName = "datafiles/datafile1.txt";
|
||||
String fileName = "datafiles/datafile2.txt";
|
||||
|
||||
//Initialise Processes. Assumes max of 10.
|
||||
Process[] p = new Process[10];
|
||||
private int processCount = -1;
|
||||
LinkedList<Process> processList = new LinkedList<Process>();
|
||||
LinkedList<Integer> randomNum = new LinkedList<>();
|
||||
|
||||
//Initialise Array for Random numbers. Assumes max of 50.
|
||||
int[] randomNum = new int[50];
|
||||
int randomNumLength = -1;
|
||||
|
||||
//Initialise Dispatcher time variable
|
||||
int disp;
|
||||
|
||||
/**
|
||||
* Main. Runs the program
|
||||
@ -29,35 +28,30 @@ public class Scheduler {
|
||||
readFile(fileName); //Read the file
|
||||
|
||||
//Test Print
|
||||
System.out.println("DISP: " + disp + "\n");
|
||||
|
||||
System.out.println("Begin Process List:");
|
||||
for (int i = 0; i <= processCount; i++)
|
||||
|
||||
for (int i = 0; i < processList.size() ; i++)
|
||||
{
|
||||
System.out.print("ID: ");
|
||||
System.out.println(p[i].getId());
|
||||
|
||||
System.out.print("Arrive: ");
|
||||
System.out.println(p[i].getArrive());
|
||||
|
||||
System.out.print("ExecSize: ");
|
||||
System.out.println(p[i].getExecSize());
|
||||
|
||||
System.out.print("Tickets: ");
|
||||
System.out.println(p[i].getTickets());
|
||||
|
||||
System.out.println("ID: " + processList.get(i).getId());
|
||||
System.out.println("Arrive: " + processList.get(i).getArrive());
|
||||
System.out.println("ExecSize: " + processList.get(i).getExecSize());
|
||||
System.out.println("Tickets: " + processList.get(i).getTickets());
|
||||
System.out.println();
|
||||
}
|
||||
System.out.println("End Process List.");
|
||||
System.out.println("End Process List.\n");
|
||||
|
||||
System.out.println("Begin Random:");
|
||||
for (int i = 0; i <= randomNumLength; i++)
|
||||
for (int i = 0; i < randomNum.size(); i++)
|
||||
{
|
||||
System.out.println(randomNum[i]);
|
||||
System.out.println(randomNum.get(i));
|
||||
}
|
||||
System.out.println("End Random.");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* readFile. Reads the file given, creating processes as needed to save details.
|
||||
* @param fileNameInput address of the file to be read in.
|
||||
*/
|
||||
@ -83,14 +77,19 @@ public class Scheduler {
|
||||
break;
|
||||
}
|
||||
|
||||
else if(line.startsWith("DISP"))
|
||||
{
|
||||
disp =Integer.parseInt(line.substring(6));
|
||||
}
|
||||
|
||||
//If the Line starts with "ID:", create a new process
|
||||
if(line.startsWith("ID:"))
|
||||
else if(line.startsWith("ID:"))
|
||||
{
|
||||
//Create new proccess
|
||||
processCount++; //Increment the number of processes.
|
||||
p[processCount] = new Process();
|
||||
Process temp = new Process();
|
||||
|
||||
p[processCount].setId(line.substring(4)); //Set the id of the proccess to whatever remains of the line after the "ID: "
|
||||
|
||||
temp.setId(line.substring(4)); //Set the id of the proccess to whatever remains of the line after the "ID: "
|
||||
|
||||
//As we've read in the ID, we shall assume the following lines (until "END") are all part of the process definition.
|
||||
while(fileReader.hasNextLine())
|
||||
@ -104,18 +103,18 @@ public class Scheduler {
|
||||
|
||||
else if(line.startsWith("Arrive:"))
|
||||
{
|
||||
p[processCount].setArrive(Integer.parseInt(line.substring(8)));
|
||||
temp.setArrive(Integer.parseInt(line.substring(8)));
|
||||
}
|
||||
|
||||
else if(line.startsWith("ExecSize:"))
|
||||
{
|
||||
|
||||
p[processCount].setSize(Integer.parseInt(line.substring(10)));
|
||||
temp.setSize(Integer.parseInt(line.substring(10)));
|
||||
}
|
||||
|
||||
else if(line.startsWith("Tickets:"))
|
||||
{
|
||||
p[processCount].setTickets(Integer.parseInt(line.substring(9)));
|
||||
temp.setTickets(Integer.parseInt(line.substring(9)));
|
||||
}
|
||||
|
||||
else
|
||||
@ -123,6 +122,8 @@ public class Scheduler {
|
||||
//Delete process?
|
||||
}
|
||||
}
|
||||
|
||||
processList.add(temp);
|
||||
}
|
||||
|
||||
//If we read the line "BEGINRANDOM", we've started the random numbers section. Until the "ENDRANDOM" line,
|
||||
@ -140,8 +141,7 @@ public class Scheduler {
|
||||
}
|
||||
else
|
||||
{
|
||||
randomNumLength++;
|
||||
randomNum[randomNumLength] = Integer.parseInt(line);
|
||||
randomNum.add(Integer.parseInt(line));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user