-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFCFS.java
More file actions
60 lines (50 loc) · 1.36 KB
/
FCFS.java
File metadata and controls
60 lines (50 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Title: FCFS.java
Name: Dylan Kapustka (Dlk190000)
Instructor: Professor Ozbirn
Course: CS 4348.001 - S21
Date: 05/01/2021
Description: FCFS class implements FCFS algorithm
*/
import java.util.ArrayList;
public class FCFS
{
//Main algorithm
public void mySchedule(ArrayList<myJob> list)
{
System.out.println("FCFS"); //Print algorithm name for graph
myJob copy;
int time = 0;
//Copy list
ArrayList<myJob> newList = new ArrayList<>();
for(myJob job: list)
{
newList.add(new myJob(job));
}
while(!(newList.isEmpty()))
{
copy = max(newList);
copy.setSpaceCount(time);
copy.printMatrix();
time += copy.getDuration();
}
}
//Helper function to find max
public myJob max(ArrayList<myJob> list)
{
myJob selected = null;
int max = 10000;
int index = 0;
for(int i = 0; i < list.size(); i++)
{
if(max >= list.get(i).getArrivalTime())
{
index = i;
max = list.get(i).getArrivalTime();
selected = list.get(i);
}
}
list.remove(index);
return selected;
}
}