diff --git a/Assignment1.java b/Assignment1.java deleted file mode 100644 index 8de53a9..0000000 --- a/Assignment1.java +++ /dev/null @@ -1,5 +0,0 @@ -public class Assignment1 { - public static void main(String[] args){ - System.out.println("Hello World!"); - } -} diff --git a/Process.java b/Process.java new file mode 100644 index 0000000..682ce08 --- /dev/null +++ b/Process.java @@ -0,0 +1,51 @@ +public class Process { + + private String id; + private int arrive; + private int execSize; + private int tickets; + + //Constructors + public Process(){ + } + + public Process(String idInput, int arriveInput, int execSizeInput, int ticketsInput) { + id = idInput; + arrive = arriveInput; + execSize = execSizeInput; + tickets = ticketsInput; + } + + //Setters + public void setId(String idInput){ + id = idInput; + } + + public void setArrive(int arriveInput){ + arrive = arriveInput; + } + + public void setSize(int execSizeInput){ + execSize = execSizeInput; + } + public void setTickets(int ticketsInput){ + tickets = ticketsInput; + } + + //Getters + public String getId(){ + return id; + } + + public int getArrive(){ + return arrive; + } + + public int getExecSize(){ + return execSize; + } + + public int getTickets(){ + return tickets; + } +} \ No newline at end of file diff --git a/README.md b/README.md index 0f4f0b5..e3708d9 100644 --- a/README.md +++ b/README.md @@ -1 +1,47 @@ -# COMP2240-Assignment1 \ No newline at end of file +# COMP2240-Assignment1 + +The assignment task is to write a program that simulates the scheduling algorithms + +* First Come First Serve (FCFS) + * Standard FCFS scheduling algorithm. Process tickets are ignored in scheduling. +* Shortest Remaining Time (SRT) + * Standard SRT scheduling algorithm. Process tickets are ignored in scheduling. +* Multi-level Feedback (Variable) (FBV) +* Lottery (LTR) + +For each algorithm, the program should list the `order and time` of the jobs being loaded in the CPU, and compute the `turnaround time` and `waiting time` for every job as well as the `average turnaround time` and `average waiting time` for the set of processes. + +The values should be put into a table in an output. + +## Pseudocode + +### Import File + +Open File + +#### Import Objects from file + +``` +IF line == BEGIN +go to next line +Set Dispatcher to value after DISP: # +go to next line +if end move on +``` + +``` +if line == ID +create new proccess object +Save: +ID +Arrive +Exec Size +Tickets +if end move on +``` + +``` +if line == begin random +import one number per line +``` + diff --git a/Scheduler.java b/Scheduler.java new file mode 100644 index 0000000..55961c2 --- /dev/null +++ b/Scheduler.java @@ -0,0 +1,128 @@ +import java.util.*; +import java.io.*; + +public class Scheduler { + //Address of File name relative to code. Replace with request for filename? + String fileName = "datafiles/datafile2.txt"; + + //Initialise Processes. Assumes max of 10. + Process[] p = new Process[10]; + private int processCount = -1; + + //Initialise Array for Random numbers. Assumes max of 50. + int[] randomNum = new int[50]; + int randomNumLength = -1; + + /** + * Main. Runs the program + */ + public static void main(String[] args){ + Scheduler system = new Scheduler(); + system.run(); + } + + /** + * Run. Most of the program starts from here. + */ + public void run() + { + readFile(fileName); //Read the file + + //Test Print + for (int i = 0; i <= randomNumLength; i++) + { + System.out.println(randomNum[i]); + } + } + + /** + * readFile. Reads the file given, creating processes as needed to save details. + * @param fileNameInput address of the file to be read in. + */ + public void readFile(String fileNameInput) + { + Scanner fileReader; //Scanner to read the file. + File dataSet = new File(fileNameInput); + + + //Try and open file. If it works, procede. + try { + fileReader = new Scanner(dataSet); + System.out.println("File Opened."); + + while(fileReader.hasNextLine()){ + String line = fileReader.nextLine(); + + if(line.equals("EOF")) + { + System.out.println("End of File Reached"); + break; + } + + //If it is a new proccess + if(line.startsWith("ID:")) + { + //Create new proccess + processCount++; + p[processCount] = new Process(); + + p[processCount].setId(line.substring(4)); + + while(fileReader.hasNextLine()) + { + line = fileReader.nextLine(); + + if(line.equals("END")) + { + break; + } + + else if(line.startsWith("Arrive:")) + { + + p[processCount].setArrive(Integer.parseInt(line.substring(8))); + } + + else if(line.startsWith("ExecSize:")) + { + + p[processCount].setSize(Integer.parseInt(line.substring(10))); + } + + else if(line.startsWith("Tickets:")) + { + p[processCount].setTickets(Integer.parseInt(line.substring(9))); + } + } + } + + else if(line.equals("BEGINRANDOM")) + { + while(fileReader.hasNextLine()) + { + line = fileReader.nextLine(); + + if(line.equals("ENDRANDOM")) + { + break; + } + else + { + randomNumLength++; + randomNum[randomNumLength] = Integer.parseInt(line); + } + } + } + } + fileReader.close(); + } + + //If the file isn't found, through a hissy fit. + catch (FileNotFoundException e) { + System.out.println("File not found."); + //e.printStackTrace(); //Optional, shows more data. + } + } + + +} diff --git a/Spec/datafile1.txt b/datafiles/datafile1.txt similarity index 100% rename from Spec/datafile1.txt rename to datafiles/datafile1.txt diff --git a/Spec/datafile1_output.txt b/datafiles/datafile1_output.txt similarity index 100% rename from Spec/datafile1_output.txt rename to datafiles/datafile1_output.txt diff --git a/Spec/datafile2.txt b/datafiles/datafile2.txt similarity index 100% rename from Spec/datafile2.txt rename to datafiles/datafile2.txt diff --git a/Spec/datafile2_output.txt b/datafiles/datafile2_output.txt similarity index 100% rename from Spec/datafile2_output.txt rename to datafiles/datafile2_output.txt