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 {
|
public class Scheduler {
|
||||||
//Address of File name relative to code. Replace with request for filename?
|
//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.
|
LinkedList<Process> processList = new LinkedList<Process>();
|
||||||
Process[] p = new Process[10];
|
LinkedList<Integer> randomNum = new LinkedList<>();
|
||||||
private int processCount = -1;
|
|
||||||
|
|
||||||
//Initialise Array for Random numbers. Assumes max of 50.
|
|
||||||
int[] randomNum = new int[50];
|
//Initialise Dispatcher time variable
|
||||||
int randomNumLength = -1;
|
int disp;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main. Runs the program
|
* Main. Runs the program
|
||||||
@ -27,37 +26,32 @@ public class Scheduler {
|
|||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
readFile(fileName); //Read the file
|
readFile(fileName); //Read the file
|
||||||
|
|
||||||
//Test Print
|
//Test Print
|
||||||
System.out.println("Begin Process List:");
|
System.out.println("DISP: " + disp + "\n");
|
||||||
for (int i = 0; i <= processCount; i++)
|
|
||||||
{
|
|
||||||
System.out.print("ID: ");
|
|
||||||
System.out.println(p[i].getId());
|
|
||||||
|
|
||||||
System.out.print("Arrive: ");
|
System.out.println("Begin Process List:");
|
||||||
System.out.println(p[i].getArrive());
|
|
||||||
|
for (int i = 0; i < processList.size() ; i++)
|
||||||
System.out.print("ExecSize: ");
|
{
|
||||||
System.out.println(p[i].getExecSize());
|
System.out.println("ID: " + processList.get(i).getId());
|
||||||
|
System.out.println("Arrive: " + processList.get(i).getArrive());
|
||||||
System.out.print("Tickets: ");
|
System.out.println("ExecSize: " + processList.get(i).getExecSize());
|
||||||
System.out.println(p[i].getTickets());
|
System.out.println("Tickets: " + processList.get(i).getTickets());
|
||||||
|
|
||||||
System.out.println();
|
System.out.println();
|
||||||
}
|
}
|
||||||
System.out.println("End Process List.");
|
System.out.println("End Process List.\n");
|
||||||
|
|
||||||
System.out.println("Begin Random:");
|
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.");
|
System.out.println("End Random.");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* readFile. Reads the file given, creating processes as needed to save details.
|
* readFile. Reads the file given, creating processes as needed to save details.
|
||||||
* @param fileNameInput address of the file to be read in.
|
* @param fileNameInput address of the file to be read in.
|
||||||
*/
|
*/
|
||||||
@ -82,15 +76,20 @@ public class Scheduler {
|
|||||||
System.out.println("End of File Reached");
|
System.out.println("End of File Reached");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if(line.startsWith("DISP"))
|
||||||
|
{
|
||||||
|
disp =Integer.parseInt(line.substring(6));
|
||||||
|
}
|
||||||
|
|
||||||
//If the Line starts with "ID:", create a new process
|
//If the Line starts with "ID:", create a new process
|
||||||
if(line.startsWith("ID:"))
|
else if(line.startsWith("ID:"))
|
||||||
{
|
{
|
||||||
//Create new proccess
|
//Create new proccess
|
||||||
processCount++; //Increment the number of processes.
|
Process temp = new Process();
|
||||||
p[processCount] = 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.
|
//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())
|
while(fileReader.hasNextLine())
|
||||||
@ -104,18 +103,18 @@ public class Scheduler {
|
|||||||
|
|
||||||
else if(line.startsWith("Arrive:"))
|
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:"))
|
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:"))
|
else if(line.startsWith("Tickets:"))
|
||||||
{
|
{
|
||||||
p[processCount].setTickets(Integer.parseInt(line.substring(9)));
|
temp.setTickets(Integer.parseInt(line.substring(9)));
|
||||||
}
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
@ -123,6 +122,8 @@ public class Scheduler {
|
|||||||
//Delete process?
|
//Delete process?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
processList.add(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If we read the line "BEGINRANDOM", we've started the random numbers section. Until the "ENDRANDOM" line,
|
//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
|
else
|
||||||
{
|
{
|
||||||
randomNumLength++;
|
randomNum.add(Integer.parseInt(line));
|
||||||
randomNum[randomNumLength] = Integer.parseInt(line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -154,5 +154,5 @@ public class Scheduler {
|
|||||||
System.out.println("File not found.");
|
System.out.println("File not found.");
|
||||||
//e.printStackTrace(); //Optional, shows more data.
|
//e.printStackTrace(); //Optional, shows more data.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user