mirror of
https://github.com/zach-sb/COMP2240-Assignment1.git
synced 2024-07-02 12:04:00 +10:00
Working File Import
This commit is contained in:
parent
d4abcb6552
commit
f152936d15
@ -1,5 +0,0 @@
|
||||
public class Assignment1 {
|
||||
public static void main(String[] args){
|
||||
System.out.println("Hello World!");
|
||||
}
|
||||
}
|
||||
51
Process.java
Normal file
51
Process.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
||||
48
README.md
48
README.md
@ -1 +1,47 @@
|
||||
# COMP2240-Assignment1
|
||||
# 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
|
||||
```
|
||||
|
||||
|
||||
128
Scheduler.java
Normal file
128
Scheduler.java
Normal file
@ -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.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user