diff --git a/Scheduler.java b/Scheduler.java index 55961c2..e2709d1 100644 --- a/Scheduler.java +++ b/Scheduler.java @@ -3,7 +3,7 @@ import java.io.*; public class Scheduler { //Address of File name relative to code. Replace with request for filename? - String fileName = "datafiles/datafile2.txt"; + String fileName = "datafiles/datafile1.txt"; //Initialise Processes. Assumes max of 10. Process[] p = new Process[10]; @@ -29,10 +29,32 @@ public class Scheduler { readFile(fileName); //Read the file //Test Print + System.out.println("Begin Process List:"); + for (int i = 0; i <= processCount; 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(); + } + System.out.println("End Process List."); + + System.out.println("Begin Random:"); for (int i = 0; i <= randomNumLength; i++) { System.out.println(randomNum[i]); } + System.out.println("End Random."); + } /** @@ -50,24 +72,27 @@ public class Scheduler { fileReader = new Scanner(dataSet); System.out.println("File Opened."); + //Progress through each line in the text file while(fileReader.hasNextLine()){ String line = fileReader.nextLine(); + //If the line has "EOF" written, stop reading lines. if(line.equals("EOF")) { System.out.println("End of File Reached"); break; } - //If it is a new proccess + //If the Line starts with "ID:", create a new process if(line.startsWith("ID:")) { //Create new proccess - processCount++; + processCount++; //Increment the number of processes. p[processCount] = new Process(); - p[processCount].setId(line.substring(4)); + p[processCount].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()) { line = fileReader.nextLine(); @@ -79,7 +104,6 @@ public class Scheduler { else if(line.startsWith("Arrive:")) { - p[processCount].setArrive(Integer.parseInt(line.substring(8))); } @@ -93,9 +117,17 @@ public class Scheduler { { p[processCount].setTickets(Integer.parseInt(line.substring(9))); } + + else + { + //Delete process? + } } } + //If we read the line "BEGINRANDOM", we've started the random numbers section. Until the "ENDRANDOM" line, + //we'll just keep reading in each number (and it is assumed each line is a single number) and adding it + //to the random number array. else if(line.equals("BEGINRANDOM")) { while(fileReader.hasNextLine()) @@ -117,12 +149,10 @@ public class Scheduler { fileReader.close(); } - //If the file isn't found, through a hissy fit. + //If the file isn't found, throw a hissy fit. catch (FileNotFoundException e) { System.out.println("File not found."); //e.printStackTrace(); //Optional, shows more data. } } - - -} +} \ No newline at end of file